Submission #303017

# Submission time Handle Problem Language Result Execution time Memory
303017 2020-09-19T18:22:51 Z Kenzo_1114 Sure Bet (CEOI17_sure) C++17
0 / 100
1 ms 384 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;

int n;
pair<double, int> a[MAXN], b[MAXN];
bool marc[MAXN];

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

	for(int i = 0; i < n; i++)
	{
		double A, B;
		scanf("%lf %lf", &A, &B);
		a[i] = make_pair(A, i);
		b[i] = make_pair(B, i);
	}	

	sort(a, a + n);
	sort(b, b + n);

	int ida = n - 1, idb = n - 1;
	double ans = (int) 0, sa = (int) 0, sb = (int) 0;
	for(int i = 0; i < n; i++)
	{
		if(sa > sb)
		{
			while(0 <= idb && marc[b[idb].second])	idb--;
			if(0 <= idb)	sb += b[idb].first, marc[b[idb].second] = true;
		}
		else
		{
			while(0 <= ida && marc[a[ida].second])	ida--;
			if(0 <= ida)	sa += a[ida].first, marc[a[ida].second] = true;
		}

		ans = max(ans, min(sa, sb) - i - 1);
	}

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

/*
	
4
1.4 3.7
1.2 2
1.6 1.4 
1.9 1.5

*/

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
sure.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |   scanf("%lf %lf", &A, &B);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -