Submission #1116648

# Submission time Handle Problem Language Result Execution time Memory
1116648 2024-11-22T03:44:42 Z shidou26 Sure Bet (CEOI17_sure) C++14
100 / 100
443 ms 5316 KB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define all(v) v.begin(), v.end()
#define dbg(v) "[" #v " = " << (v) << "]"

template<typename T> bool maximize(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}else return false;
}
template<typename T> bool minimize(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}else return false;
}

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;

const int N = 1e5 + 3;

int n;
double a[N], b[N];

namespace subtask1 {
	double best = 0;

	void backtrack(int p, double totalA, double totalB, int counter) {
		if(p > n) {
			maximize(best, min(totalA - (double)counter, totalB - (double)counter));
			return;
		}
		backtrack(p + 1, totalA, totalB, counter);
		backtrack(p + 1, totalA + a[p], totalB, counter + 1);
		backtrack(p + 1, totalA, totalB + b[p], counter + 1);
		backtrack(p + 1, totalA + a[p], totalB + b[p], counter + 2);
	}

	void solve() {
		backtrack(1, 0, 0, 0);
		cout << fixed << setprecision(4) << best << endl;
	}
};

namespace subtask3 {
	double prefA[N], prefB[N];

	bool check(double x, int p) {
		int limitA = lower_bound(prefA + 1, prefA + 1 + n, x) - prefA;
		int limitB = lower_bound(prefB + 1, prefB + 1 + n, x) - prefB;
		if(limitA == n + 1 || limitB == n + 1)
			return false;
		else return (limitA + limitB <= p);
	}

	void solve() {
		sort(a + 1, a + 1 + n, greater<double>());
		sort(b + 1, b + 1 + n, greater<double>());

		for(int i = 1; i <= n; i++) prefA[i] = prefA[i - 1] + a[i];
		for(int i = 1; i <= n; i++) prefB[i] = prefB[i - 1] + b[i];

		double best = 0;
		for(int p = 1; p <= 2 * n; p++) {
			double l = 0, r = 1e9 + 3;
			for(int rep = 1; rep <= 50; rep++) {
				double mid = (l + r) / 2.0;
				if(check(mid, p)) {
					l = mid;
				}else r = mid;
			}
			maximize(best, l - p);
		}
		cout << fixed << setprecision(4) << best << endl;
	}
}

void process() {
	if(n <= 10) {
		subtask1::solve();
		return;
	}	

	subtask3::solve();
}


void input() {
	cin >> n;

	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
	}	
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	#define task "DateALive"
	if(fopen(task".INP", "r")) {
		freopen(task".INP", "r", stdin);
		freopen(task".OUT", "w", stdout);
	}

	input();
	process();

	return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:107:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |   freopen(task".INP", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:108:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |   freopen(task".OUT", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 4 ms 2384 KB Output is correct
4 Correct 5 ms 2384 KB Output is correct
5 Correct 4 ms 2384 KB Output is correct
6 Correct 4 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 4 ms 2384 KB Output is correct
4 Correct 5 ms 2384 KB Output is correct
5 Correct 4 ms 2384 KB Output is correct
6 Correct 4 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 2 ms 2384 KB Output is correct
9 Correct 1 ms 2552 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 4 ms 2552 KB Output is correct
13 Correct 4 ms 2384 KB Output is correct
14 Correct 4 ms 2552 KB Output is correct
15 Correct 4 ms 2384 KB Output is correct
16 Correct 4 ms 2544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 4 ms 2384 KB Output is correct
4 Correct 5 ms 2384 KB Output is correct
5 Correct 4 ms 2384 KB Output is correct
6 Correct 4 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 2 ms 2384 KB Output is correct
9 Correct 1 ms 2552 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 4 ms 2552 KB Output is correct
13 Correct 4 ms 2384 KB Output is correct
14 Correct 4 ms 2552 KB Output is correct
15 Correct 4 ms 2384 KB Output is correct
16 Correct 4 ms 2544 KB Output is correct
17 Correct 433 ms 4936 KB Output is correct
18 Correct 443 ms 4944 KB Output is correct
19 Correct 419 ms 4732 KB Output is correct
20 Correct 415 ms 4928 KB Output is correct
21 Correct 419 ms 5192 KB Output is correct
22 Correct 426 ms 4940 KB Output is correct
23 Correct 426 ms 4936 KB Output is correct
24 Correct 411 ms 4952 KB Output is correct
25 Correct 416 ms 4936 KB Output is correct
26 Correct 422 ms 5316 KB Output is correct