Submission #492144

# Submission time Handle Problem Language Result Execution time Memory
492144 2021-12-05T15:39:19 Z Biaz Sure Bet (CEOI17_sure) C++17
100 / 100
84 ms 3652 KB
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define Nanase_Kurumi_aka_menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<double,int>
#define ALL(i) i.begin(),i.end()
#define gcd(i,j) __gcd(i,j)
#define fi first
#define se second
#define eps 0.00000001
#define ist insert
#define DNE nullptr
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
int max(int x,int y){return x>=y?x:y;}
int min(int x,int y){return x>=y?y:x;}
using namespace std;
typedef int ll;
const int N=1000005;
const int M=1000005;
const int MOD=1000000007;//998244353;
const int INF=1000000000000000000;//2147483647;

double a[N],b[N];
int n;
double ans;
inline void sol(){
    cin >>n;
    for (int i=1;i<=n;i++){
        cin >>a[i]>>b[i];
        //a[i]-=1,b[i]-=1;
    }
    sort(a+1,a+n+1,greater<double>());
    sort(b+1,b+n+1,greater<double>());
    b[n+1]=MOD;
    a[n+1]=MOD;
    //for (int i=1;i<=n;i++)
        //b[i]+=b[i-1];
    double ca=0,cb=0;
    int la=1,lb=1;
    for (int i=1;i<=2*n;i++){
        if (fabs(ca+a[la]-cb)<fabs(cb+b[lb]-ca)){
            ca+=a[la++];
        }
        else{
            cb+=b[lb++];
        }
        ans=max(ans,min(ca,cb)-i);
    }
    cout <<fixed<<setprecision(4)<<ans<<'\n';
}
/*
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
*/
signed main(){
    Nanase_Kurumi_aka_menhera_chan_is_mine
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 73 ms 1836 KB Output is correct
18 Correct 68 ms 3208 KB Output is correct
19 Correct 70 ms 3212 KB Output is correct
20 Correct 73 ms 3144 KB Output is correct
21 Correct 84 ms 3652 KB Output is correct
22 Correct 80 ms 3152 KB Output is correct
23 Correct 71 ms 3244 KB Output is correct
24 Correct 73 ms 3240 KB Output is correct
25 Correct 70 ms 3244 KB Output is correct
26 Correct 77 ms 3608 KB Output is correct