A
#include<bits/stdc++.h> #define ll long long #define endl "\n" using namespace std; template<class T> void printff(vector<T>& v) { for (auto k : v) cout << k << " "; cout << endl; } void SOLVE() { int n; cin >> n; vector<ll> a(n); for(auto & val : a) cin >> val; ll sum = 0; ll mx = 0; for(int i = 0; i < n; i++){ sum += a[i]; mx = max(mx, sum); if(sum < 0) sum = 0; cout << mx << " "; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc = 1; cin >> tc; while(tc--) SOLVE(); return 0; }
Leave a Comment