#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b){
return a.first < b.first;
}
int main(){
int n;
cin >> n;
int a,b;
//一定记得打空格 不然会编译不通过
vector<pair<int, int> > stu(n);
for(int i = 0;i <n;i++){
cin>>a>>b;
stu[i] = make_pair(a,b);
}
sort(stu.begin(), stu.end(), cmp);
//先计算最小的正确率并记录小于该阈值的最后一个下标
int count = 0;
int maxCount = -1;
int index = 0;
int maxTheta = stu[0].first;
int nowTheta = maxTheta;
for(int i = 0;i < n;i++){
if(stu[i].first >= nowTheta && stu[i].second == 1){
count++;
}else if(stu[i].first < nowTheta && stu[i].second == 0){
count++;
index = i;
}
}
maxCount = count;
//遍历vector,查找到下一个阈值,对index+1到阈值前的一部分进行判断,如果新阈值判断对了,说明旧阈值判断的是错的,+1,否则-1
for(int i = 1;i < n;i++){
if(nowTheta == stu[i].first){
continue;
}
nowTheta = stu[i].first;
while(stu[index].first < nowTheta){
if(stu[index].second == 1){
count--;
}else{
count++;
}
index++;
}
if(count >= maxCount){
maxCount = count;
maxTheta = nowTheta;
}
}
cout<<maxTheta<<endl;
return 0;
}
CCF-CSP记录 202012-2
最新推荐文章于 2022-03-21 21:03:53 发布