fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5.  
  6. void solve() {
  7. int n;
  8. cin >> n;
  9. vector<ll> a(n);
  10. for (int i = 0; i < n; i++) cin >> a[i];
  11. ll ans = accumulate(a.begin(), a.end(), 0ll);
  12. for (int i = 1; i < n; i++) {
  13. ll sum = 0;
  14. for (int j = n - 1; j >= i; j--) {
  15. a[j] -= a[j - 1];
  16. sum += a[j];
  17. }
  18. ans = max(max(ans, sum), -sum);
  19. }
  20. cout << ans << endl;
  21. }
  22.  
  23. int main() {
  24. int t;
  25. cin >> t;
  26. while (t--) solve();
  27. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
1
-1000
2
5 -3
2
1000 1
9
9 7 9 -9 9 -8 7 -8 9
11
678 201 340 444 453 922 128 987 127 752 0
stdout
-1000
8
1001
2056
269891