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. int sum = 0,maximum=0;
  13.  
  14. for (int i = 0; i < n; i++) {
  15. cin >> a[i];
  16. sum += a[i];
  17. if(a[i]<2*(i+1)){
  18. maximum=max(maximum,2*(i+1)-a[i]);
  19. }
  20. }
  21.  
  22. cout << max((n+1)*n,sum+maximum) << "\n";
  23. }
  24.  
  25. int32_t main() {
  26. fast_io;
  27. int t;
  28. cin >> t;
  29. while (t--) solve();
  30. return 0;
  31. }
  32.  
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
20
30