QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#322717 | #7689. Flipping Cards | liuzhenhao09# | WA | 2ms | 8016kb | C++20 | 644b | 2024-02-07 16:09:49 | 2024-02-07 16:09:49 |
Judging History
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'