Submission #533105

#TimeUsernameProblemLanguageResultExecution timeMemory
533105cig32Sure Bet (CEOI17_sure)C++17
100 / 100
88 ms5072 KiB
#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 (stderr)

sure.cpp: In function 'int main()':
sure.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
sure.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%lf %lf", &a[i], &b[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...