Submission #501279

# Submission time Handle Problem Language Result Execution time Memory
501279 2022-01-02T17:50:11 Z Ziel Sure Bet (CEOI17_sure) C++17
100 / 100
86 ms 3628 KB
/**
 * LES GREATEABLES BRO TEAM
**/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = false;
void setIO(const string &f = "");

void solve() {
    int n;
    cin >> n;
    vector<double> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++) {
    	cin >> a[i] >> b[i];
    }
    sort(a.begin() + 1, a.end(), greater<double>());
    sort(b.begin() + 1, b.end(), greater<double>());
	for (int i = 1; i <= n; i++) {
		a[i] += a[i - 1];
		b[i] += b[i - 1];
	}

	double aa = 0, bb = 0;
	for (int i = 1; i <= n; i++) {
		int lo = 1, hi = n, idx = 0;
		while (hi >= lo) {
			int mid = (lo + hi) / 2;
			if (a[mid] <= b[i])
				lo = mid + 1, idx = mid;
			else
				hi = mid - 1;
		}
		if (min(a[idx] - i - idx, b[i] - i - idx) > min(aa, bb)) {
			aa = a[idx] - i - idx;
			bb = b[i] - i - idx;
		}
	}
	for (int i = 1; i <= n; i++) {
		int lo = 1, hi = n, idx = 0;
		while (hi >= lo) {
			int mid = (lo + hi) / 2;
			if (b[mid] <= a[i])
				lo = mid + 1, idx = mid;
			else
				hi = mid - 1;
		}
		if (min(a[i] - i - idx, b[idx] - i - idx) > min(aa, bb)) {
			aa = a[i] - i - idx;
			bb = b[idx] - i - idx;
		}
	}
	cout << fixed << setprecision(4) << min(aa, bb);
}

signed main() {
    setIO();
    
    int tt = 1;
    if (FLAG) {
    	cin >> tt;
    }
    while (tt--) {
    	solve();
    }
    
    return 0;
}

void setIO(const string &f) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen((f + ".in").c_str(), "r")) {
        freopen((f + ".in").c_str(), "r", stdin);
        freopen((f + ".out").c_str(), "w", stdout);
    }
}

Compilation message

sure.cpp: In function 'void setIO(const string&)':
sure.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen((f + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 83 ms 3144 KB Output is correct
18 Correct 85 ms 3140 KB Output is correct
19 Correct 82 ms 3272 KB Output is correct
20 Correct 79 ms 3252 KB Output is correct
21 Correct 85 ms 3528 KB Output is correct
22 Correct 85 ms 3272 KB Output is correct
23 Correct 81 ms 3156 KB Output is correct
24 Correct 78 ms 3148 KB Output is correct
25 Correct 76 ms 3140 KB Output is correct
26 Correct 86 ms 3628 KB Output is correct