QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#395375 | #7689. Flipping Cards | zzuqy# | WA | 1ms | 9992kb | C++14 | 828b | 2024-04-21 13:53:38 | 2024-04-21 13:53:39 |
Judging History
answer
#include <bits/stdc++.h>
#define N 1000009
using namespace std;
int n, a[N], b[N];
int s[N], maxx[N], sum[N];
bool ok(int mid) {
for (int i = 1; i <= n; i++)
s[i] = (a[i] >= mid) - (b[i] >= mid);
int maxxx = -1e9;
for (int i = 1; i <= n; i++)
sum[i] = sum[i - 1] + s[i];
for (int i = n; i; i--)
maxx[i] = max(maxx[i + 1], sum[i]);
for (int i = 1; i <= n; i++)
maxxx = max(maxxx, maxx[i] - sum[i]);
maxxx = max(maxxx, maxx[1]);
for (int i = 1; i <= n; i++)
maxxx += (a[i] >= mid);
return maxxx >= n / 2 + 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i], &b[i]);
int l = 1, r = 1000000000, ans;
while (l <= r) {
int mid = (l + r) >> 1;
if (ok(mid))
l = mid + 1, ans = mid;
else
r = mid - 1;
}
cout << ans;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9940kb
input:
5 3 6 5 2 4 7 6 4 2 8
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9992kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 9896kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 9884kb
input:
99 749159996 323524232 125448341 365892333 481980673 143665393 394405973 44741918 687549448 513811513 287088118 385131171 11865696 666468353 449920567 373650719 671547289 116780561 41003675 671513243 351534153 507850962 374160874 985661954 222519431 600582098 987220654 704142246 856147059 37783620 1...
output:
581718566
result:
wrong answer 1st numbers differ - expected: '528957505', found: '581718566'