답안 #498411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498411 2021-12-25T06:32:39 Z Ziel Sure Bet (CEOI17_sure) C++17
60 / 100
2000 ms 1952 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];
	}
	for (int i = 1; i <= n; i++) {
		a[i] -= i;
		b[i] -= i;
	}

	double aa = 0, bb = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= min(int(a[i]), n); j++) {
			if (i <= int(b[j])) {
				if (min(aa, bb) < min(a[i] - j, b[j] - i)) {
					aa = a[i] - j;
					bb = b[j] - i;
				}
			}
		}
	}
	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:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen((f + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 320 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 312 KB Output is correct
16 Correct 4 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 320 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 312 KB Output is correct
16 Correct 4 ms 320 KB Output is correct
17 Execution timed out 2047 ms 1952 KB Time limit exceeded
18 Halted 0 ms 0 KB -