Skip to content

Instantly share code, notes, and snippets.

@tina1998612
Created November 12, 2016 09:17
Show Gist options
  • Save tina1998612/cb775b67f527f2b41284fe0a77ce2984 to your computer and use it in GitHub Desktop.
Save tina1998612/cb775b67f527f2b41284fe0a77ce2984 to your computer and use it in GitHub Desktop.
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
#define N 100000+10
using namespace std;
int n,a,cnt[N],adder[N],maxi,fst,from,to;
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++) {
scanf("%d",&a);
if(a && a<n){
to=(i-a+n)%n;
from=i+1;
if(from>=n) from-=n;
if(from>to){
adder[0]++;
adder[to+1]--;
adder[from]++;
}
else{
adder[from]++;
adder[to+1]--;
}
}
}
cnt[0]=adder[0];
maxi=cnt[0];
for(int i=1;i<n;i++){
cnt[i]+=cnt[i-1]+adder[i];
if(cnt[i]>maxi){
maxi=cnt[i];
}
}
fst=N;
for(int i=0;i<n;i++)
if(maxi==cnt[i]) fst=min(fst,i);
printf("%d\n",fst+1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment