QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#253191 | #7689. Flipping Cards | chunzhifeng | WA | 1ms | 7480kb | C++14 | 859b | 2023-11-16 19:38:44 | 2023-11-16 19:38:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define endl "\n"
#define PII pair<int,int>
const ll INF=0x3f3f3f3f3f3f3f3f;
const int mod=998244353;
const int N=2e6+5;
int a[N],b[N],t[N];
void solve(){
int n; cin>>n;
for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
auto check=[&](int x){
int sum=0;
for(int i=1;i<=n;i++){
if(a[i]>=x&&b[i]<x) t[i]=-1;
else if(a[i]<x&&b[i]>=x) t[i]=1;
else t[i]=0,sum+=a[i]>=x?1:-1;
}
int ans=0,s=0;
for(int i=1;i<=n;i++){
s+=t[i];
s=max(s,0);
ans=max(ans,s);
} return sum+ans>0;
};
int l=1,r=1e9,ans=l;
while(l<=r){
int mid=l+r>>1;
if(check(mid)) ans=mid,l=mid+1;
else r=mid-1;
} cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T=1; //cin>>T;
while(T--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7480kb
input:
5 3 6 5 2 4 7 6 4 2 8
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 7416kb
input:
1 2 1
output:
1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'