fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5.  
  6.  
  7. void solve() {
  8. ll n;
  9. cin >> n;
  10. vector<ll> a(n);
  11. for(ll i=0;i<n;i++) cin >> a[i];
  12. vector<ll> c(n),suffix(n);
  13. ll sum = 0;
  14. ll ma=a[0];
  15. for(ll i=0;i<n;i++){
  16. sum+=a[n-1-i];
  17. suffix[i]=sum;
  18. }
  19. for(ll i=1;i<n;i++){
  20. ma=max(ma,a[i-1]);
  21. c[i]=ma;
  22. }
  23. for(ll i=0;i<n;i++){
  24. if(i==0) cout << *max_element(a.begin(),a.end()) << " ";
  25. else {ll ans = max(suffix[i],suffix[i-1]+c[n-1-i]);
  26. cout << ans << " ";}
  27. }
  28. cout << '\n';
  29. }
  30.  
  31. int main(){
  32. ios::sync_with_stdio(false);
  33. cin.tie(nullptr);
  34.  
  35. int t;
  36. cin >> t;
  37. while (t--) solve();
  38.  
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.01s 5288KB
stdin
4
7
13 5 10 14 8 15 13
6
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1
42
2
7 5
stdout
15 28 42 50 63 73 78 
1000000000 2000000000 3000000000 4000000000 5000000000 6000000000 
42 
7 12