QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253191#7689. Flipping CardschunzhifengWA 1ms7480kbC++14859b2023-11-16 19:38:442023-11-16 19:38:44

Judging History

你现在查看的是最新测评结果

  • [2023-11-16 19:38:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7480kb
  • [2023-11-16 19:38:44]
  • 提交

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();
}

Details

Tip: Click on the bar to expand more detailed information

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'