Submission #130920

#TimeUsernameProblemLanguageResultExecution timeMemory
130920DiuvenSure Bet (CEOI17_sure)C++14
100 / 100
104 ms3708 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef pair<int, int> pii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int n;
double X[MAX], Y[MAX], ans;

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>X[i]>>Y[i];
	sort(X+1, X+n+1, greater<double>());
	sort(Y+1, Y+n+1, greater<double>());

	for(int i=1, j=1, k=1; i<=n; i++){
		static double a=0, b1=0, b2=0, c1=0, c2=0;
		a += X[i], c1++, c2++;
		while(j<=n && b1<a) b1 += Y[j++], c1++;
		while(k<=n && b2+Y[k]<=a && Y[k]>=1) b2 += Y[k++], c2++;
		if(a<=b1) ans = max(ans, a-c1);
		if(b2<=a) ans = max(ans, b2-c2);
	}

	cout<<fixed;
	cout.precision(4);
	cout<<ans<<'\n';

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...