#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define N 1000005
using namespace std;
using namespace __gnu_pbds;
typedef tree<pii, null_type, less<pii>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n;
double a[100005];
double b[100005];
int main()
{
cin >> n;
ff(i,1,n){
cin >> a[i] >> b[i];
}
sort(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
reverse(a + 1, a + n + 1);
reverse(b + 1, b + n + 1);
int p1 = 1, p2 = 1;
double s1 = 0;
double s2 = 0;
int kol = 0;
double res = 0;
while(p1 <= n || p2 <= n){
if(p1 == n+1){
s2 += b[p2];
p2++;
kol++;
res = max(res, min(s1,s2) - kol);
continue;
}
else if(p2 == n+1){
s1 += a[p1];
p1++;
kol++;
res = max(res, min(s1,s2) - kol);
continue;
}
if(s1 < s2){
s1 += a[p1];
p1++;
kol++;
}
else{
s2 += b[p2];
p2++;
kol++;
}
res = max(res, min(s1,s2) - kol);
}
cout << fixed << setprecision(6) << res << "\n";
return 0;
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
sure.cpp:29:5: note: in expansion of macro 'ff'
29 | ff(i,1,n){
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |