QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#247273 | #7689. Flipping Cards | ucup-team1074 | WA | 1ms | 7672kb | C++20 | 858b | 2023-11-11 13:52:46 | 2023-11-11 13:52:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
typedef pair<int, int> PII;
int a[N], b[N];
PII c[N];
int idx[N];
int n;
bool cmp (int x, int y) {
return c[x] < c[y];
}
bool check(int x) {
int y = x - 1 - (n - 1) / 2;
int cnt = 0;
for (int i = 1; i < x; i++) {
if (c[idx[i]].second >= c[idx[x]].first)
cnt++;
}
return cnt >= y;
}
int main () {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
c[i] = { a[i], b[i] };
idx[i] = i;
}
sort (idx + 1, idx + n + 1, cmp);
// for (int i = 1; i <= n; i++) {
// cout << c[idx[i]].first << " " << c[idx[i]].second << endl;
// }
int l = ((n + 1) / 2), r = n;
while (l < r) {
int mid = (l + r + 1) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << c[idx[l]].first << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7364kb
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: 0ms
memory: 7672kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 7620kb
input:
1 212055293 384338286
output:
212055293
result:
wrong answer 1st numbers differ - expected: '384338286', found: '212055293'