답안 #45297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45297 2018-04-12T17:00:01 Z bugmenot111 Sure Bet (CEOI17_sure) C++17
100 / 100
146 ms 18492 KB
/*
maximize min(s[a] - (a + b), s[b] - (a + b))
min(s[a], s[b]) - (a + b)
min(s[a], s[b]) - b
*/
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <functional>
#define MAXN 100100
double a[MAXN];
double b[MAXN];
double pa[MAXN];
double pb[MAXN];
int n;
int main(void) {
	double best = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%lf %lf", &a[i], &b[i]);
	}
	std::sort(a, a + n, std::greater<double>());
	std::sort(b, b + n, std::greater<double>());
	std::partial_sum(a, a + n, pa);
	std::partial_sum(b, b + n, pb);
	for(int i = 0; i < n; i++) {
		double x = pa[i];
		double y1 = 0, y2 = 0;
		auto it = std::upper_bound(pb, pb + n, x);
		if(it != pb + n) y1 = std::min(x, *it) - std::distance(pb, it) - i - 2;
		if(it != pb) it = std::prev(it);
		y2 = std::min(x, *it) - std::distance(pb, it) - i - 2;
		best = std::max(best, std::max(y1, y2));
	}
	printf("%.4lf", best);
	return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
sure.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lf %lf", &a[i], &b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 3 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 4 ms 740 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
15 Correct 4 ms 844 KB Output is correct
16 Correct 4 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 3 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 4 ms 740 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
15 Correct 4 ms 844 KB Output is correct
16 Correct 4 ms 876 KB Output is correct
17 Correct 128 ms 5248 KB Output is correct
18 Correct 130 ms 6680 KB Output is correct
19 Correct 117 ms 8008 KB Output is correct
20 Correct 97 ms 9528 KB Output is correct
21 Correct 118 ms 11228 KB Output is correct
22 Correct 93 ms 12604 KB Output is correct
23 Correct 95 ms 13956 KB Output is correct
24 Correct 117 ms 15360 KB Output is correct
25 Correct 91 ms 16612 KB Output is correct
26 Correct 146 ms 18492 KB Output is correct