You are viewing a single comment's thread. Return to all comments →
**Easiest C++ solution: **
int arr[100005], dp[100005];
int main() { int n; cin>>n;
for(int i=0; i<n; i++) { cin>>arr[i]; dp[i]=0; } for(int i=0; i<n; i++) { int l= (i-arr[i]+1)%n; if(l<0) l= n+l; int r; if(i==n-1) r=0; else r=i+1; if(l>=r) dp[0]+=1; dp[l]+=1; dp[r]-=1; } for(int i=1; i<n; i++) { dp[i]=dp[i]+dp[i-1]; } int maxi=INT_MIN, ind=0; for(int i=0; i<n; i++) { dp[i]=(n-dp[i]); if(dp[i]>maxi) { maxi=dp[i]; ind=i; } } cout<<ind+1<<endl;
} `
Seems like cookies are disabled on this browser, please enable them to open this website
Kindergarten Adventures
You are viewing a single comment's thread. Return to all comments →
**Easiest C++ solution: **
int arr[100005], dp[100005];
int main() { int n; cin>>n;
} `