Submission #303054

#TimeUsernameProblemLanguageResultExecution timeMemory
303054pedroslreySure Bet (CEOI17_sure)C++17
100 / 100
78 ms2164 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	scanf("%d", &n);

	vector<double> xs, ys;
	for (int i = 0; i < n; ++i) {
		double x, y;
		scanf("%lf%lf", &x, &y);

		xs.push_back(x);
		ys.push_back(y);
	}

	sort(xs.rbegin(), xs.rend());
	sort(ys.rbegin(), ys.rend());

	double sum_x = 0, sum_y = 0;
	int stop_x = 0, stop_y = 0;
	double ans = 0;

	for (int i = 1; i <= 2*n; ++i) {
		if (sum_x < sum_y && stop_x < n)
			sum_x += xs[stop_x], ++stop_x;
		else if (sum_x >= sum_y && stop_y < n)
			sum_y += ys[stop_y], ++stop_y;

		ans = max(ans, min(sum_x, sum_y) - i);
	}

	printf("%.4f\n", ans);
}

Compilation message (stderr)

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