Submission #1221464

#TimeUsernameProblemLanguageResultExecution timeMemory
1221464Nika533Sure Bet (CEOI17_sure)C++20
100 / 100
46 ms5072 KiB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int,int>
using namespace std;
int n,m,T,k;
void test_case() {
	scanf("%d",&n);
	double a[n+1],b[n+1];
	for (int i=1; i<=n; i++) scanf("%lf%lf",&a[i],&b[i]);
	sort(a+1,a+1+n); reverse(a+1,a+1+n);
	sort(b+1,b+1+n); reverse(b+1,b+1+n);
	double prefa[n*2+1],prefb[n*2+1]; prefa[0]=0; prefb[0]=0;
	for (int i=1; i<=n; i++) {
		prefa[i]=prefa[i-1]+a[i];
		prefb[i]=prefb[i-1]+b[i];
	}
	for (int i=n+1; i<=n*2; i++) {
		prefa[i]=prefa[i-1];
		prefb[i]=prefb[i-1];
	}
	double ans=0;
	for (double x=0; x<=n*2; x++) {
		double anss=0;
		int l=0,r=x;
		while (l<=r) {
			int mid=(l+r)/2;
			int mid2=x-mid;
			anss=max(anss,min(prefa[mid],prefb[mid2]));
			if (prefa[mid]>prefb[mid2]) {
				r=mid-1;
			}
			else {
				l=mid+1;
			}
		}
		anss-=x;
		ans=max(ans,anss);
	}
	printf("%.4lf",(double)ans);
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	T=1;
	while (T--) test_case();
}

Compilation message (stderr)

sure.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
sure.cpp: In function 'void test_case()':
sure.cpp:15:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   15 |         scanf("%d",&n);
      |                ~^  ~~
      |                 |  |
      |                 |  long long int*
      |                 int*
      |                %lld
sure.cpp: At global scope:
sure.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main () {
      | ^~~~
sure.cpp: In function 'void test_case()':
sure.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
sure.cpp:17:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         for (int i=1; i<=n; i++) 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...