fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fast_io ios::sync_with_stdio(false); cin.tie(NULL)
  5. #define int long long
  6.  
  7. void solve() {
  8. int n;
  9. cin >> n;
  10.  
  11. vector<int> a(n);
  12. for (int i = 0; i < n; i++) cin >> a[i];
  13.  
  14. long long baseSum = accumulate(a.begin(), a.end(), 0LL);
  15.  
  16. long long bestGain = 0;
  17.  
  18. for (int i = 0; i < n; i++) {
  19. long long sum1 = 0;
  20.  
  21. for (int j = i; j < n; j++) {
  22.  
  23. if (a[j] >= (i + j + 2)) break;
  24.  
  25. sum1 += a[j];
  26.  
  27. long long newSum = 1LL * (j - i + 1) * (i + j + 2);
  28. long long gain = newSum - sum1;
  29.  
  30. bestGain = max(bestGain, gain);
  31. }
  32. }
  33.  
  34. cout << baseSum + bestGain << "\n";
  35. }
  36.  
  37. int32_t main() {
  38. fast_io;
  39. int t;
  40. cin >> t;
  41. while (t--) solve();
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.01s 5308KB
stdin
4
3
2 5 1
2
4 4
4
1 3 2 1
5
3 2 0 9 10
stdout
13
8
19
32