QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322717#7689. Flipping Cardsliuzhenhao09#WA 2ms8016kbC++20644b2024-02-07 16:09:492024-02-07 16:09:49

Judging History

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

  • [2024-02-07 16:09:49]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8016kb
  • [2024-02-07 16:09:49]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e16 + 7;
int n;
int a[300010],b[300010],f[300010];
bool check(int k){
	int ans = -INF,res = 0;
	for(int i = 1; i <= n; i++){
		int v = (int)(b[i] >= k) - (int)(a[i] >= k);
		res += (int)(a[i] >= k);
		f[i] = max(0LL,f[i - 1]) + v;
		ans = max(ans,f[i]);
	}
	return res + ans >= (n + 1) / 2;
}
signed main(){
	scanf("%lld",&n);
	for(int i = 1; i <= n; i++) scanf("%lld %lld",&a[i],&b[i]);
	int l = 1,r = 1e9;
	while(l < r){
		int mid = (l + r + 1) >> 1;
		if(check(mid)) l = mid;
		else r = mid - 1;
	}
	printf("%lld",l);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 8016kb

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: 2ms
memory: 7944kb

input:

1
2 1

output:

1

result:

wrong answer 1st numbers differ - expected: '2', found: '1'