#include <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
int n;
ld a[100009], b[100009];
int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n;
for(int i = 0; i < n; ++i){
scanf("%Lf", &a[i]);
scanf("%Lf", &b[i]);
}
sort(a, a+n, greater<ld>());
sort(b, b+n, greater<ld>());
ld ans = 0;
ld aProfit = 0;
int aIndex = 0;
ld bProfit = 0;
int bIndex = 0;
int spent = 0;
while(aIndex < n || bIndex < n){
spent += 1;
if(aIndex < n && (bIndex >= n || aProfit < bProfit)){
aProfit += a[aIndex++];
} else{
bProfit += b[bIndex++];
}
ans = max(ans, min(aProfit, bProfit)-spent);
}
printf("%.4lf", (double)ans);
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%Lf", &a[i]);
| ~~~~~^~~~~~~~~~~~~~
sure.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%Lf", &b[i]);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
260 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
260 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
260 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
60 ms |
4696 KB |
Output is correct |
18 |
Correct |
67 ms |
4792 KB |
Output is correct |
19 |
Correct |
61 ms |
4792 KB |
Output is correct |
20 |
Correct |
61 ms |
4752 KB |
Output is correct |
21 |
Correct |
73 ms |
5068 KB |
Output is correct |
22 |
Correct |
62 ms |
4812 KB |
Output is correct |
23 |
Correct |
61 ms |
4796 KB |
Output is correct |
24 |
Correct |
62 ms |
4792 KB |
Output is correct |
25 |
Correct |
63 ms |
4744 KB |
Output is correct |
26 |
Correct |
64 ms |
5084 KB |
Output is correct |