답안 #80450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
80450 2018-10-20T19:56:33 Z shoemakerjo Sure Bet (CEOI17_sure) C++14
100 / 100
148 ms 21740 KB
#include <bits/stdc++.h>

using namespace std;

#define double long double
#define maxn 100010

int n;

vector<double> a, b;
double apref[maxn];
double bpref[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	double ca, cb;
	for (int i = 1; i <= n; i++) {
		cin >> ca >> cb;
		a.push_back(ca);
		b.push_back(cb);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	double ans = 0;

	for (int i = 1; i <= n; i++) {
		apref[i] = apref[i-1] + a[i-1];
		bpref[i] = bpref[i-1] + b[i-1];
	}

	for (int i = 1; i <= n; i++) {
		double aprof = apref[i] - i;

		int lo = 1;
		int hi = n; 
		//binary search to find first index such that b profit is greater than a profit

		if (bpref[n] - i - n < aprof - n) {
			ans = max(ans, bpref[n] - i - n);
			continue;
		}

		while (lo < hi) {
			int mid = (lo + hi)/2;
			if (bpref[mid] - i - mid < aprof - mid) {
				//did not go far enough
				lo = mid+1;
			}
			else hi = mid;
		}
		ans = max(ans, bpref[lo-1] - (lo-1) - i);
		ans = max(ans, aprof - lo);

	}


	cout << fixed << setprecision(4);
	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 2 ms 528 KB Output is correct
8 Correct 3 ms 752 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 2 ms 752 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 3 ms 764 KB Output is correct
13 Correct 3 ms 892 KB Output is correct
14 Correct 3 ms 924 KB Output is correct
15 Correct 3 ms 956 KB Output is correct
16 Correct 3 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 2 ms 528 KB Output is correct
8 Correct 3 ms 752 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 2 ms 752 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 3 ms 764 KB Output is correct
13 Correct 3 ms 892 KB Output is correct
14 Correct 3 ms 924 KB Output is correct
15 Correct 3 ms 956 KB Output is correct
16 Correct 3 ms 972 KB Output is correct
17 Correct 136 ms 8640 KB Output is correct
18 Correct 132 ms 10052 KB Output is correct
19 Correct 136 ms 11500 KB Output is correct
20 Correct 128 ms 12880 KB Output is correct
21 Correct 142 ms 14524 KB Output is correct
22 Correct 134 ms 15984 KB Output is correct
23 Correct 134 ms 17324 KB Output is correct
24 Correct 148 ms 18876 KB Output is correct
25 Correct 135 ms 20008 KB Output is correct
26 Correct 140 ms 21740 KB Output is correct