# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1276739 | herominhsteve | Sure Bet (CEOI17_sure) | C++20 | 49 ms | 2008 KiB |
#include <bits/stdc++.h>
#define el '\n'
#define FNAME "sure"
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x,n) memset(x,(n),sizeof(x))
using namespace std;
const long long MOD = (long long) 1e9+7;
template<class X,class Y> bool minimize(X &a,Y b){ if (a>b) {a=b; return true;} return false;}
template<class X,class Y> bool maximize(X &a,Y b){ if (a<b) {a=b; return true;} return false;}
void setup(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if (fopen(FNAME".inp","r")){
freopen(FNAME".inp","r",stdin);
freopen(FNAME".out","w",stdout);
}
}
int n;
vector<double> a,b;
void init(){
cin>>n;
a.resize(n);
b.resize(n);
for (int i=0;i<n;i++) cin>>a[i]>>b[i];
}
void sol(){
sort(a.rbegin(),a.rend());
sort(b.rbegin(),b.rend());
int ptrA=0,ptrB=0;
double curA=0.0 ,curB=0.0,res=0.0;
for (int i=1;i<=2*n;i++){
if (curA < curB){
if (ptrA==n) break;
curA += a[ptrA++];
} else{
if (ptrB==n) break;
curB += b[ptrB++];
}
maximize(res,min(curA,curB) - i);
}
cout<<fixed<<setprecision(4)<<res;
}
int main(){
setup();
init();
sol();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |