Codeforces Good Bye 2023 1916C - Training Before the Olympiad Solution


 

Problem Link : https://codeforces.com/contest/1916/problem/C

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n , x ; cin >> n ;
  11. long long ans = 0 ;
  12. int even = 0 , odd = 0 , v ;
  13. for ( int i = 0 ; i < n ; i++){
  14. cin >> x ;
  15. ans += x ;
  16. if ( x % 2 == 0) even++ ;
  17. else odd++ ;
  18. v = odd / 3 ;
  19. if ( even == 0 and odd == 1 ){
  20. v = 0 ;
  21. }
  22. else if (odd % 3 == 1 ) {
  23. v = (odd + 2 )/ 3 ;
  24. }
  25. cout << ans - v <<" " ;
  26. }
  27. cout <<'\n' ;
  28. }
  29. return 0 ;
  30. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.