QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245596 | #7689. Flipping Cards | UNos_maricones# | WA | 1ms | 5700kb | C++14 | 958b | 2023-11-10 04:08:15 | 2023-11-10 04:08:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef pair <int,int> pii;
const int N = 300'005;
int n;
int a[N], b[N];
bool check ( int med ) {
int cnt_a = 0, cnt_change = 0, curr_max_change = 0;
for ( int i = 0; i < n; ++i ) {
cnt_a += a[i] < med;
curr_max_change = (b[i] < med) - (a[i] < med) + min ( 0, curr_max_change );
cnt_change = min ( cnt_change, curr_max_change );
}
return (cnt_a + cnt_change) <= n/2;
}
int main () {
#ifndef LOCAL
#endif
scanf ( "%d", &n );
for ( int i = 0; i < n; ++i ) {
scanf ( "%d%d", a+i, b+i );
}
int lo = 1, hi = 1e9, mi;
while ( lo < hi ) {
mi = (lo+hi)/2;
if ( check ( mi ) )
lo = mi+1;
else
hi = mi;
}
printf ( "%d\n", lo-1 );
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3604kb
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: 3532kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5700kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3536kb
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:
528957505
result:
ok 1 number(s): "528957505"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3672kb
input:
101 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...
output:
999999999
result:
wrong answer 1st numbers differ - expected: '1000000000', found: '999999999'