답안 #1027198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027198 2024-07-19T01:57:54 Z toan2602 Sure Bet (CEOI17_sure) C++14
100 / 100
55 ms 2764 KB
#include<bits/stdc++.h>

using namespace std;
int n;
double a[100005], b[100005], pfs[100005];
void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
	sort(a+1,a+1+n, greater<>());
	sort(b+1,b+1+n, greater<>());
	for (int i = 1; i <= n; i++) pfs[i] = pfs[i-1] + b[i];
	double ra, rb, res = 0;
	ra = rb = 0;
	for (int i = 1; i <= n; i++) {
		ra += a[i], rb = 0;
		int l = 1, r = n, mid, pos=n;
		while(l <= r) {
			mid = (l+r)/2;
			if(pfs[mid] > ra) r = mid-1, pos = min(pos, mid);
			else l = mid+1;
		}
		res = max(res, min(ra-i-pos, pfs[pos]-i-pos));
		if(pos != 1) pos--, res = max(res, min(ra-i-pos, pfs[pos]-i-pos));
	}
	cout << fixed << setprecision(4) << res;
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen("input.inp","r")){
		freopen("input.inp", "r", stdin);
		freopen("output.out", "w", stdout);
	}
	int t = 1;
	// cin >> t;
	while(t--) {
		solve();
	}
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   freopen("input.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen("output.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 52 ms 2644 KB Output is correct
18 Correct 52 ms 2652 KB Output is correct
19 Correct 52 ms 2628 KB Output is correct
20 Correct 51 ms 2644 KB Output is correct
21 Correct 54 ms 2644 KB Output is correct
22 Correct 53 ms 2764 KB Output is correct
23 Correct 52 ms 2604 KB Output is correct
24 Correct 53 ms 2640 KB Output is correct
25 Correct 52 ms 2608 KB Output is correct
26 Correct 55 ms 2644 KB Output is correct