#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>
#define fi first
#define se second
#define TASK "surebet"
#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define pb push_back
#define MASK(i) (1 << (i))
#define BIT(x, i) ((x >> (i)) & 1)
using namespace std;
const int oo = 1e9 + 7;
const ll loo = (ll)1e18 + 7;
const int N = 1e5 + 7;
int n;
long double a[N], b[N], res, pre[N], pre2[N];
void trau(int i, vector<int> state){
if (i == n){
long double l = 0, r = 0, penalty = 0;
for (int i = 0; i < state.size(); i++) {
if (state[i] == 3) penalty -= 2;
else if (state[i] != 4) penalty--;
}
for (int i = 0; i < state.size(); i++) if (state[i] != 4) {
if (state[i] != 2){
l += a[i + 1];
}
if (state[i] != 1){
r += b[i + 1];
}
}
res = max(res, min(l, r) + penalty);
return ;
}
for (int j = 1; j <= 4; j++){
vector<int> newstate = state;
newstate.pb(j);
trau(i + 1, newstate);
}
}
int bs(long double cursum){
int l = 1, r = n, ret = -1;
while (l <= r){
int middle = (r + l) / 2;
if (pre2[middle] >= cursum) {
ret = middle;
r = middle - 1;
}
else l = middle + 1;
}
return ret;
}
int bs2(long double cursum){
int l = 1, r = n, ret = -1;
while (l <= r){
int middle = (r + l) / 2;
if (pre[middle] >= cursum) {
ret = middle;
r = middle - 1;
}
else l = middle + 1;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen(TASK".inp", "r", stdin);
// freopen(TASK".out", "w", stdout);
// Nhớ tắt file
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i] >> b[i];
}
if (n <= 10){
vector<int> temp;
trau(0, temp);
cout << fixed << setprecision(4) << res;
}
else if (n <= 1000){
sort(a + 1, a + 1 + n, greater<long double>());
sort(b + 1, b + 1 + n, greater<long double>());
for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
for (int i = 1; i <= n; i++) pre2[i] = pre2[i - 1] + b[i];
for (int i = 0; i <= n; i++){
for (int j = 0; j <= n; j++){
res = max(res, min(pre[i], pre2[j]) - i - j);
}
}
cout << fixed << setprecision(4) << res;
}
else {
sort(a + 1, a + 1 + n, greater<long double>());
sort(b + 1, b + 1 + n, greater<long double>());
for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
for (int i = 1; i <= n; i++) pre2[i] = pre2[i - 1] + b[i];
for (int i = 1; i <= n; i++){
long double cursum = pre[i];
int numget = bs(cursum);
if (numget != -1){
res = max(res, cursum - i - numget);
}
}
for (int i = 1; i <= n; i++){
long double cursum = pre2[i];
int numget = bs2(cursum);
if (numget != -1){
res = max(res, cursum - i - numget);
}
}
cout << fixed << setprecision(4) << res;
}
return 0;
}
Compilation message
sure.cpp: In function 'void trau(int, std::vector<int>)':
sure.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 0; i < state.size(); i++) {
| ~~^~~~~~~~~~~~~~
sure.cpp:33:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < state.size(); i++) if (state[i] != 4) {
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
201 ms |
340 KB |
Output is correct |
4 |
Correct |
186 ms |
340 KB |
Output is correct |
5 |
Correct |
202 ms |
340 KB |
Output is correct |
6 |
Correct |
184 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
201 ms |
340 KB |
Output is correct |
4 |
Correct |
186 ms |
340 KB |
Output is correct |
5 |
Correct |
202 ms |
340 KB |
Output is correct |
6 |
Correct |
184 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
340 KB |
Output is correct |
13 |
Correct |
5 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
420 KB |
Output is correct |
15 |
Correct |
6 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
201 ms |
340 KB |
Output is correct |
4 |
Correct |
186 ms |
340 KB |
Output is correct |
5 |
Correct |
202 ms |
340 KB |
Output is correct |
6 |
Correct |
184 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
340 KB |
Output is correct |
13 |
Correct |
5 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
420 KB |
Output is correct |
15 |
Correct |
6 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
340 KB |
Output is correct |
17 |
Correct |
113 ms |
6552 KB |
Output is correct |
18 |
Correct |
99 ms |
6840 KB |
Output is correct |
19 |
Correct |
122 ms |
6904 KB |
Output is correct |
20 |
Correct |
109 ms |
6912 KB |
Output is correct |
21 |
Correct |
111 ms |
6900 KB |
Output is correct |
22 |
Correct |
121 ms |
6904 KB |
Output is correct |
23 |
Correct |
112 ms |
6904 KB |
Output is correct |
24 |
Correct |
101 ms |
6920 KB |
Output is correct |
25 |
Correct |
115 ms |
7124 KB |
Output is correct |
26 |
Correct |
108 ms |
6860 KB |
Output is correct |