Skip to content

Instantly share code, notes, and snippets.

@akhal3d96
Forked from nagy3n/gist:9a0306212c3cd9efa581
Last active August 29, 2015 14:25
Show Gist options
  • Save akhal3d96/7bcebd8cc5f1354d243b to your computer and use it in GitHub Desktop.
Save akhal3d96/7bcebd8cc5f1354d243b to your computer and use it in GitHub Desktop.
Solution of Div312#2 Problem B http://codeforces.com/contest/558/problem/B
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int times[1000001],indst[1000001],inden[1000001],n,i,f,maxn,max;
maxn=-1;
scanf("%d",&n);
memset(times, 0, 1000001*sizeof(int));
for(i=0;i<n;i++)
{
scanf("%d",&f);
times[f]+=1;
if(times[f]==1)
indst[f]=i+1;
inden[f]=i+1;
if(times[f]>maxn)
{
max=f;
maxn=times[f];
}
else if(times[f]==maxn)
{
if((inden[max]-indst[max])>(inden[f]-indst[f]))
max=f;
}
}
printf("%d %d",indst[max],inden[max]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment