Submission #305135

# Submission time Handle Problem Language Result Execution time Memory
305135 2020-09-22T15:43:39 Z miss_robot Sure Bet (CEOI17_sure) C++14
100 / 100
118 ms 4472 KB
#include <bits/stdc++.h>

#pragma GCC optimize("O3")

using namespace std;

double f(int x, int y, vector<double>& a, vector<double>& b){
	return min(a[x], b[y])-x-y;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << setprecision(4) << fixed;
	int n;
	double sol = 0;
	cin >> n;
	vector<double> a(n), b(n);
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	a.insert(a.begin(), 0);
	b.insert(b.begin(), 0);
	for(int i = 1; i <= n; i++) a[i] += a[i-1], b[i] += b[i-1];
	for(int i = 0; i <= n; i++){
		int l = 0, h = n, m;
		while(l < h){
			if(l == h-1){
				if(f(i, l, a, b) > f(i, h, a, b)) h--;
				else l++;
			}
			else{
				m = (l+h)/2;
				if(f(i, m, a, b) >= f(i, m+1, a, b)) h = m;
				else l = m+1;
			}
		}
		sol = max(sol, f(i, l, a, b));
	}
	cout << sol << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 108 ms 4088 KB Output is correct
18 Correct 108 ms 4100 KB Output is correct
19 Correct 110 ms 4088 KB Output is correct
20 Correct 111 ms 4092 KB Output is correct
21 Correct 113 ms 4472 KB Output is correct
22 Correct 108 ms 4088 KB Output is correct
23 Correct 111 ms 4216 KB Output is correct
24 Correct 110 ms 4200 KB Output is correct
25 Correct 118 ms 4088 KB Output is correct
26 Correct 114 ms 4472 KB Output is correct