Educational Codeforces Round 112 (Rated for Div. 2) 1555C - Coin Rows Solution


 

Problem Link : https://codeforces.com/problemset/problem/1555/C

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. using ll = long long ;
  5. int32_t main() {
  6. ios_base::sync_with_stdio(0);
  7. cin.tie(0);
  8. int t;
  9. cin >> t;
  10. while (t--) {
  11. int n ;
  12. cin >> n ;
  13. int a[n+1] , b[n+1] ;
  14. for ( int i = 0 ; i < n ; i++ ) cin >> a[i] ;
  15. for ( int i = 0 ; i < n ; i++ ) cin >> b[i] ;
  16. ll sum1[n+1] , sum2[n+1] ;
  17. sum1[0] = a[0] ;
  18. for ( int i = 1 ; i < n ; i++) {
  19. sum1[i] = sum1[i - 1] + a[i] ;
  20. }
  21. sum2[0] = b[0] ;
  22. for ( int i = 1 ; i < n ; i++) {
  23. sum2[i] = sum2[i - 1] + b[i] ;
  24. }
  25. ll ans = sum1[n-1] - a[0] ;
  26. for ( int i = 1 ; i < n ; i++ ){
  27. ll x = sum2[i-1] ;
  28. ll y = sum1[n-1] - sum1[i] ;
  29. ans = min ( ans , max ( x , y )) ;
  30. }
  31. cout << ans << endl;
  32. }
  33. }

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 &g...

Powered by Blogger.