# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1027222 |
2024-07-19T02:12:18 Z |
idkman |
Sure Bet (CEOI17_sure) |
C++17 |
|
1 ms |
2396 KB |
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(ll i=(a);i<=(b);i++)
#define Ford(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define endl "\n"
using namespace std;
int Dx[] = {0, 1, 0, -1, -1, -1, 1, 1};
int Dy[] = {-1, 0, 1, 0, 1, -1, 1, -1};
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
const ll inf = 1000000000000000000;
const int N = 100000;
const int block_size = 300;
const ll MOD = 1e9 + 7; /* 998244353 */
const int LG = 18;
const int K = 20;
const int M = 10000000;
ll nph(ll k, ll x) { return ((x >> k) & 1LL); }
#define ld double
ll n;
ld a[N+3],b[N+3], prea[N+3], preb[N+3];
bool cmp(ld a, ld b) {
return a > b;
}
ld result(vector<ld> a, vector<ld> b) {
ld sum1 = 0;
for(auto x : a) sum1 += x;
ld sum2 = 0;
for(auto x : b) sum2 += x;
return min(sum1, sum2) - 1.0 * (a.size() + b.size());
}
void Solve() {
cin>>n;
ld ans = 0.0;
For(i, 1, n) cin>>a[i]>>b[i];
sort(a+1, a+n+1, cmp); sort(b+1, b+n+1, cmp);
For(i, 1, n) prea[i] = prea[i-1] + a[i];
For(i, 1, n) preb[i] = preb[i-1] + b[i];
//For(i, 1, n) cout << preb[i] << endl;
// pick biggest first first
ll l = 1, r = 1;
vector<ld> used1, used2;
while(l <= n && r <= n) {
ll amount = a[l]; amount--;
if(amount == 0) break; // 1 2 3 4 5
ld have = preb[r + amount - 1] - preb[r-1];
have -= 1.0 * (amount + 1);
if(have > 0) {
used1.pb(a[l]);
For(i, r, r+amount-1) used2.pb(b[i]);
r += amount;
}
l++;
}
//for(auto x : used2) cout << x << " ";
ans = max(ans, result(used1, used2));
used1.clear(); used2.clear();
For(i, 1, n) swap(a[i], b[i]);
l = 1; r = 1;
while(l <= n && r <= n) {
ll amount = a[l]; amount--;
if(amount == 0) break; // 1 2 3 4 5
ld have = preb[r + amount - 1] - preb[r-1];
have -= 1.0 * (amount + 1);
if(have > 0) {
used1.pb(a[l]);
For(i, r, r+amount-1) used2.pb(b[i]);
r += amount;
}
l++;
}
//for(auto x : used2) cout << x << " ";
ans = max(ans, result(used1, used2));
cout << fixed << setprecision(4) << ans;
}
int main() {
// freopen("AVGSEQ.INP", "r", stdin);
// freopen("AVGSEQ.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
//cin >> t;
while(t--)
Solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |