Codeforces Round 912 (Div. 2) 1903C - Theofanis' Nightmare Solution
Problem Link : https://codeforces.com/contest/1903/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 ; cin >> n ;
- int a[n+2] ;
- for ( int i = 0 ; i < n ; i++){
- cin >> a[i] ;
- }
- long long suf[n+1] = {0};
- for ( int i = n - 1 ; i >= 0 ; i--){
- suf[i] = a[i] + suf[i+1] ;
- }
- long long ans = suf[0] ;
- for ( int i = 1 ; i < n ; i++){
- if(suf[i] > 0){
- ans += suf[i] ;
- }
- }
- cout << ans <<'\n';
- }
- return 0 ;
- }
No comments