Table Sum, INOI 2012
Problem Description​
Question : Table Sum, INOI 2012
Submit Code : Codechef
Prerequisites​
Arrays
Solution​
Let see how the solution will be affected by rotating the second table.
You can see that each answer can be calculated through previous calculated answers.
Code​
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> arr(n);
for(int& i : arr)
cin >> i;
vector<int> bmax(n);
bmax[0] = arr[0]+1;
for(int i=1;i<n;i++)
bmax[i] = max(bmax[i-1], arr[i]+i+1);
int emax = 0;
for(int i=0;i<n;i++){
cout << max(bmax[n-i-1]+i, emax) << " ";
emax = 1 + max(arr[n-i-1], emax);
}
return 0;
}