답안 #80449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
80449 2018-10-20T19:52:29 Z shoemakerjo Sure Bet (CEOI17_sure) C++14
0 / 100
2 ms 704 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 504 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Incorrect 2 ms 704 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Incorrect 2 ms 704 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Incorrect 2 ms 704 KB Output isn't correct
4 Halted 0 ms 0 KB -