Submission #471108

# Submission time Handle Problem Language Result Execution time Memory
471108 2021-09-07T06:04:25 Z Killer2501 Sure Bet (CEOI17_sure) C++14
100 / 100
159 ms 2752 KB
#include<bits/stdc++.h>

using namespace std;
 
const int N=1e5+5;
int n;
long long a[N],b[N];
long long s[N], mod = 1e9;
 
bool check(long long lim)
{
    long long cur=0;
    for(int i=1;i<=n;i++)
    {
        cur+=a[i];
        long long mx=(cur-lim)/mod-i;
        if(mx<0) continue;
        mx=min(mx,1ll*n);
        if(s[mx]-mod*i>=lim) return true;
    }
    return false;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=1;i<=n;i++)
    {	
      	double x;
        cin>> x;
        a[i] =mod*x;
      	cin >> x;
        b[i] = mod * x;
    }
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    reverse(a+1,a+n+1);
    reverse(b+1,b+n+1);
    for(int i=1;i<=n;i++) s[i]=max(s[i-1],s[i-1]+b[i]-mod);
    long long l=1,r=1e18,res=0;
    while(l<=r)
    {
        long long mid=(l+r)/2;
        if(check(mid))
        {
            res=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    cout<<fixed<<setprecision(4)<<1.0*r/mod;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:42:26: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   42 |     long long l=1,r=1e18,res=0;
      |                          ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 122 ms 2552 KB Output is correct
18 Correct 129 ms 2644 KB Output is correct
19 Correct 133 ms 2608 KB Output is correct
20 Correct 132 ms 2752 KB Output is correct
21 Correct 148 ms 2616 KB Output is correct
22 Correct 124 ms 2632 KB Output is correct
23 Correct 123 ms 2636 KB Output is correct
24 Correct 131 ms 2548 KB Output is correct
25 Correct 136 ms 2636 KB Output is correct
26 Correct 159 ms 2640 KB Output is correct