以下为100分代码,仅供参考。
题目链接
C++代码
#include<bits/stdc++.h>
using namespace std;
struct node{
int y;
int result;
}s[100005];
int cmp( node a,node b )
{
return a.y<b.y;
}
vector<int> v;
map<int,int> mp,mp0,mp1;
int main()
{
int m,one=0,max,ans;
int tem[100005];
ios::sync_with_stdio(0);
cin.tie(0);
cin>>m;
for( int i=0; i<m; i++ )
{
cin>>s[i].y>>s[i].result;
if( !mp[s[i].y] )
{
v.push_back(s[i].y);
mp[s[i].y]++;
}
}
sort(s,s+m,cmp);
sort(v.begin(),v.end());
for( int i=0; i<m; i++ )
{
if( s[i].result == 0 )
mp0[s[i].y]++;
else
mp1[s[i].y]++,one++;
}
max = one;
tem[0] = one;
ans = v[0];
for( int i=1; i<v.size(); i++ )
{
tem[i] = tem[i-1] + mp0[v[i-1]] - mp1[v[i-1]];
if( tem[i] >= max )
{
tem[i] = max;
ans = v[i];
}
}
cout<<ans;
return 0;
}