Educational Codeforces Round 112 (Rated for Div. 2) 1555C - Coin Rows Solution
Problem Link : https://codeforces.com/problemset/problem/1555/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long ;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ;
- cin >> n ;
- int a[n+1] , b[n+1] ;
- for ( int i = 0 ; i < n ; i++ ) cin >> a[i] ;
- for ( int i = 0 ; i < n ; i++ ) cin >> b[i] ;
- ll sum1[n+1] , sum2[n+1] ;
- sum1[0] = a[0] ;
- for ( int i = 1 ; i < n ; i++) {
- sum1[i] = sum1[i - 1] + a[i] ;
- }
- sum2[0] = b[0] ;
- for ( int i = 1 ; i < n ; i++) {
- sum2[i] = sum2[i - 1] + b[i] ;
- }
- ll ans = sum1[n-1] - a[0] ;
- for ( int i = 1 ; i < n ; i++ ){
- ll x = sum2[i-1] ;
- ll y = sum1[n-1] - sum1[i] ;
- ans = min ( ans , max ( x , y )) ;
- }
- cout << ans << endl;
- }
- }
No comments