Skip to content

Instantly share code, notes, and snippets.

@ngobach
Created September 18, 2016 17:17
Show Gist options
  • Save ngobach/e67a5079a359dc0ef0f8c8bea75437b2 to your computer and use it in GitHub Desktop.
Save ngobach/e67a5079a359dc0ef0f8c8bea75437b2 to your computer and use it in GitHub Desktop.
P161PROC.CPP
#include <iostream>
using namespace std;
int main(){
// freopen("input.txt","r",stdin);
int n,k;
cin>>n>>k;
int a[n+5] = {0},t = 1, b[n+5] = {0};
cin>>a[0];
while(n-1 > 0){
n--;
int c;
cin>>c;
if(c == a[t-1]) continue;
a[t] = c;
t++;
}
int stress,result = -1,kq = 1,d,c;
// for(int i = 1;i<=k;i++){
// stress = t-1;
// d = 0,c = t-1;
// while(a[d] == i) stress--,d++;
// while(a[c] == i) stress--,c--;
// for(int j = d+1;j <c;j++){
// if(a[j] == i && a[j-1] == a[j+1]) stress -= 2;
// else if(a[j] == i)stress--;
// }
// if(result > stress) result = stress,kq = i;
// }
for (int i=1;i<t-1;i++) {
if (a[i-1]==a[i+1]) b[a[i]] += 2; else b[a[i]] ++;
}
b[a[0]]++;
b[a[t-1]]++;
for (int i=1;i<=k;i++) {
if (b[i]>result) {
kq = i;
result = b[i];
}
}
cout<<kq;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment