#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 100001;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 30013;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;
double a[NMAX];
double b[NMAX];
int n;
double place(double bets) {
int sum = 0, i = 1, j = 1;
double sa = 0, sb = 0, init = bets;
while(bets--) {
if(sa == sb) {
///poate mai facem ceva modificari
if(j > n) {
sa += a[i];
i++;
continue;
}
if(i > n) {
sb += b[j];
j++;
continue;
}
if(a[i] > b[j]) {
sb += b[j];
j++;
continue;
}
sa += a[i];
i++;
} else if(sa < sb) {
if(i > n) {
sb += b[j];
j++;
continue;
}
sa += a[i];
i++;
} else if(sa > sb) {
if(j > n) {
sa += a[i];
i++;
continue;
}
sb += b[j];
j++;
}
}
return min(sa - init, sb - init);
}
int main() {
int i;
cin >> n;
for(i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
reverse(b + 1, b + n + 1);
double maxim = 0;
for(i = 1; i <= 2 * n; i++){
maxim = max(maxim, place(i));
}
cout << fixed << setprecision(4) << maxim;
return 0;
}
Compilation message
sure.cpp: In function 'double place(double)':
sure.cpp:28:9: warning: unused variable 'sum' [-Wunused-variable]
28 | int sum = 0, i = 1, j = 1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
7 ms |
204 KB |
Output is correct |
14 |
Correct |
7 ms |
204 KB |
Output is correct |
15 |
Correct |
8 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
7 ms |
204 KB |
Output is correct |
14 |
Correct |
7 ms |
204 KB |
Output is correct |
15 |
Correct |
8 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
204 KB |
Output is correct |
17 |
Execution timed out |
2070 ms |
1800 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |