Submission #930664

# Submission time Handle Problem Language Result Execution time Memory
930664 2024-02-20T09:07:19 Z oblantis Sure Bet (CEOI17_sure) C++17
100 / 100
68 ms 5208 KB
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 1e6 + 1;

void solve() {
	int n;
	cin >> n;
	double a[n], b[n], a0[n], b0[n], ans = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	sort(a, a + n), sort(b, b + n);
	for(int i = 0; i < n; i++){
		a0[i] = a[i] - 2;
		b0[i] = b[i] - 2;
		a[i]--, b[i]--;
		if(i)a[i] += a[i - 1], b[i] += b[i - 1];
	}
	double s = 0, t = 0;
	for(int i = n - 1; i >= 0; i--){
		s += a0[i], t += b0[i];
		ans = max(ans, min(s, t));
		int l = -1, r = i;
		if(s < t){
			while(l + 1 < r){
				int mid = l + (r - l) / 2;
				if(t - (i - mid) > s + (i ? a[i - 1] : 0) - (mid ? a[mid - 1] : 0))r = mid;
				else l = mid;
			}
			ans = max(ans, s + (i ? a[i - 1] : 0) - (r ? a[r - 1] : 0));
			if(r)ans = max(ans, t - (i - r) - 1);
		}
		else if(s > t){
			while(l + 1 < r){
				int mid = l + (r - l) / 2;
				if(s - (i - mid) > t + (i ? b[i - 1] : 0) - (mid ? b[mid - 1] : 0))r = mid;
				else l = mid;
			}
			ans = max(ans, t + (i ? b[i - 1] : 0) - (r ? b[r - 1] : 0));
			if(r){
				ans = max(ans, s - (i - r) - 1);
			}
		}
	}
	cout << fixed << setprecision(4) << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int times = 1;
	//cin >> times;
	for(int i = 1; i <= times; i++) {
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 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 0 ms 348 KB Output is correct
12 Correct 1 ms 604 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 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 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 0 ms 348 KB Output is correct
12 Correct 1 ms 604 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 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 61 ms 4932 KB Output is correct
18 Correct 62 ms 4932 KB Output is correct
19 Correct 68 ms 4816 KB Output is correct
20 Correct 65 ms 4932 KB Output is correct
21 Correct 66 ms 5208 KB Output is correct
22 Correct 61 ms 4828 KB Output is correct
23 Correct 60 ms 4696 KB Output is correct
24 Correct 62 ms 4928 KB Output is correct
25 Correct 64 ms 5096 KB Output is correct
26 Correct 67 ms 5204 KB Output is correct