#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const ll MAXN = 1e6 + 10;
ll n;
double a[MAXN];
double b[MAXN];
double max_win;
void read()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
}
bool cmp(double x, double y)
{
return x > y;
}
void solve()
{
sort(a + 1, a + n + 1, cmp);
sort(b + 1, b + n + 1, cmp);
ll idxa = 1;
ll idxb = 1;
double suma = 0.0;
double sumb = 0.0;
while(idxa <= n)
{
suma += a[idxa++];
while(idxb <= n && min(suma - idxb + 1, sumb - idxa + 1) < min(suma - idxb, sumb + b[idxb] - idxa + 1))
{
sumb += b[idxb];
idxb++;
}
max_win = max(max_win, min(suma - idxb + 1, sumb - idxa + 1));
}
cout << fixed << setprecision(4) << max_win << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
50 ms |
3392 KB |
Output is correct |
18 |
Correct |
50 ms |
3388 KB |
Output is correct |
19 |
Correct |
49 ms |
3392 KB |
Output is correct |
20 |
Correct |
49 ms |
3152 KB |
Output is correct |
21 |
Correct |
52 ms |
3676 KB |
Output is correct |
22 |
Correct |
48 ms |
3164 KB |
Output is correct |
23 |
Correct |
49 ms |
3156 KB |
Output is correct |
24 |
Correct |
51 ms |
3160 KB |
Output is correct |
25 |
Correct |
54 ms |
3384 KB |
Output is correct |
26 |
Correct |
52 ms |
3756 KB |
Output is correct |