Codeforces Good Bye 2023 1916C - Training Before the Olympiad Solution
Problem Link : https://codeforces.com/contest/1916/problem/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n , x ; cin >> n ;
- long long ans = 0 ;
- int even = 0 , odd = 0 , v ;
- for ( int i = 0 ; i < n ; i++){
- cin >> x ;
- ans += x ;
- if ( x % 2 == 0) even++ ;
- else odd++ ;
- v = odd / 3 ;
- if ( even == 0 and odd == 1 ){
- v = 0 ;
- }
- else if (odd % 3 == 1 ) {
- v = (odd + 2 )/ 3 ;
- }
- cout << ans - v <<" " ;
- }
- cout <<'\n' ;
- }
- return 0 ;
- }
No comments