# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
865360 |
2023-10-24T07:41:13 Z |
vjudge1 |
Sure Bet (CEOI17_sure) |
C++17 |
|
0 ms |
348 KB |
#include <bits/stdc++.h>
#define ll long long
#define Sayan ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define Int(a,x) a+1 , a+1+x
#define sz() size()
#define F first
#define S second
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define pii pair<ll,ll>
using namespace std ;
const ll N = 1e5+5;
const ll INF = 1e18;
const ll mod = 1e9+7;
/*
ll binpow(ll a , ll b){
if(b == 0) return 1;
if(b%2) return binpow(a , b-1) * a % mod;
ll c = binpow(a , b/2) % mod;
return c*c%mod;
}
*/
double l[N],r[N];
void solve(){
ll n;
cin>>n;
double mx=0;
set<double>st1,st2;
double sum1,sum2;
for(ll i=1;i<=n;i++){
cin>>l[i]>>r[i];
sum1+=l[i];
sum2+=r[i];
st1.insert(l[i]);
st2.insert(r[i]);
}
double cnt1=n,cnt2=n;
mx=max(mx,min(sum1-(n*2),sum2-(n*2)));
sort(l+1,l+1+n);
reverse(l+1,l+1+n);
sort(r+1,r+1+n);
reverse(r+1,r+1+n);
for(ll i=n*2-1;i>=2;i--){
if(cnt1==1){
cnt2--;
double mn=*st2.begin();
sum2-=mn;
st2.erase(*st2.begin());
}
else if(cnt2==1){
cnt1--;
double mn=*st1.begin();
sum1-=mn;
st1.erase(*st1.begin());
}
else {
if(sum1>=sum2){
cnt1--;
double mn=*st1.begin();
sum1-=mn;
st1.erase(*st1.begin());
}
else {
cnt2--;
double mn=*st2.begin();
sum2-=mn;
st2.erase(*st2.begin());
}
}
// cout<<sum1<<" "<<sum2<<" "<<i<<"\n";
mx=max(mx,min(sum1-i,sum2-i));
}
cout<<fixed<<setprecision(4)<<mx<<"\n";
}
signed main () {
Sayan;
ll t=1;
//cin>>t;
while(t--)solve();
}
Compilation message
sure.cpp: In function 'void solve()':
sure.cpp:52:8: warning: 'sum2' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | sum2-=mn;
| ~~~~^~~~
sure.cpp:62:4: warning: 'sum1' may be used uninitialized in this function [-Wmaybe-uninitialized]
62 | if(sum1>=sum2){
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |