#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define float double
#define endl "\n"
using namespace std;
bool f(float a, float b){
return a>b;
}
int binarySearch(vector<float>&arr, int l, int r, float x){
if(arr[l]>=x)
return l;
if(arr[l+1]>=x)
return l;
if(arr[r]<=x)
return r-1;
while (l < r) {
if(l+1==r)
return l;
int m = (l+r) / 2;
if(arr[m]<=x && arr[m+1]>=x)
return m;
if (arr[m+1] < x)
l = m;
else
r = m;
}
return -1;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
float n;
cin>>n;
vector<float>a(n);
vector<float>b(n);
for(float i=0;i<n;i++){
cin>>a[i]>>b[i];
}
sort(a.begin(),a.end(),f);
sort(b.begin(),b.end(),f);
vector<float>b_pref;
float s=0;
b_pref.push_back(0);
for(float i=0;i<n;i++){
s+=b[i];
b_pref.push_back(s);
}
s=0;
float score=0;
for(float i=0;i<n;i++){
s+=a[i];
float j=binarySearch(b_pref,0,n,s);
float s1=min(s,b_pref[j])-i-j-1;
float s2=min(s,b_pref[j+1])-i-j-2;
score=max(score,s2);
score=max(score,s1);
}
printf("%.4lf",(float)score);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
428 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
428 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
73 ms |
4428 KB |
Output is correct |
18 |
Correct |
74 ms |
4308 KB |
Output is correct |
19 |
Correct |
75 ms |
4328 KB |
Output is correct |
20 |
Correct |
73 ms |
4308 KB |
Output is correct |
21 |
Correct |
78 ms |
4824 KB |
Output is correct |
22 |
Correct |
79 ms |
4544 KB |
Output is correct |
23 |
Correct |
74 ms |
4328 KB |
Output is correct |
24 |
Correct |
74 ms |
4308 KB |
Output is correct |
25 |
Correct |
73 ms |
4312 KB |
Output is correct |
26 |
Correct |
77 ms |
4816 KB |
Output is correct |