题目连接:
http://118.190.20.162/view.page?gpid=T122
代码:
#include <iostream>
#include<algorithm>
using namespace std;
typedef struct student{
int x;
int y;
}student;
bool cmp(student c,student d){
if(c.x!=d.x) return c.x<d.x;
else return c.y<d.y;
}
student a[10000];
int main(){
int m;
cin>>m;
a[0].x=1;
a[0].y=1;
int max=0;
int best=0;
for(int i=1;i<=m;i++){
cin>>a[i].x>>a[i].y;
}
sort(a+1,a+m+1,cmp);
for(int i=1;i<=m;i++){
if(a[i-1].x==a[i].x) continue;
int count;
int p=0,q=0;
for(int j=0;j<i;j++){
if(a[j].y==0) p++;
}
for(int j=i;j<m;j++){
if(a[j].y==1)q++;
}
count=p+q;
if(count>=max){
max=count;
best=a[i].x;
}
}
cout<<best<<endl;
}