QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#490320 | #7689. Flipping Cards | ucup-team3160# | WA | 0ms | 3876kb | C++14 | 794b | 2024-07-25 14:35:51 | 2024-07-25 14:35:51 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std ;
const int INF = 1e9 ;
int n ;
int a[300005] , b[300005] ;
bool check( int x )
{
int s = 0 , minv = 0 ;
int tot = 0 ;
int res = 0 ;
for ( int i = 1 ; i <= n ; i++ )
{
int nv = 0 ;
if ( a[i] >= x )
{
tot++ ;
if ( b[i] >= x ) nv = 0 ;
else nv = -1 ;
}
else if ( b[i] >= x ) nv = 1 ;
else nv = 0 ;
s = s + nv ;
res = max( res , s - minv ) ;
minv = min( minv , s ) ;
}
return tot + res >= ( x + 1 ) / 2 ;
}
int main()
{
scanf("%d" , &n) ;
for ( int i = 1 ; i <= n ; i++ ) scanf("%d%d" , a + i , b + i) ;
int l = 1 , r = INF ;
while ( l < r )
{
int mid = ( l + r + 1 ) >> 1 ;
if ( check( mid ) ) l = mid ;
else r = mid - 1 ;
}
printf("%d\n" , l) ;
return 0 ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
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: 3756kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3876kb
input:
1 212055293 384338286
output:
2
result:
wrong answer 1st numbers differ - expected: '384338286', found: '2'