Submission #1027220

# Submission time Handle Problem Language Result Execution time Memory
1027220 2024-07-19T02:10:46 Z vjudge1 Sure Bet (CEOI17_sure) C++17
100 / 100
81 ms 6540 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 2e18;
const ll blocksz = 320;
const ll N = 1e5 + 8;
ld a[N],b[N],preA[N],preB[N];
ll n;
void solve(){
    cin >> n;
    for(ll i = 1; i <= n; i++) cin >> a[i] >> b[i];
    sort(a+1,a+n+1,greater<ld>());
    sort(b+1,b+n+1,greater<ld>());
    for(ll i = 1; i <= n; i++){
        preA[i] = preA[i-1]+a[i];
        preB[i] = preB[i-1]+b[i];
    }
    ld ans = 0;
    for(ll i = 1; i <= n; i++){
        ll l = 1, r = n;
        ll pos = -1;
        while(l <= r){
            ll m = l+r>>1;
            if(preB[m] >= preA[i]){
                r = m-1;;
                pos = m;
            }
            else l = m+1;;
        }
        if(pos == -1) continue;
        ans = max(ans,preA[i]-(ld)i-(ld)pos);
    }
    for(ll i = 1; i <= n; i++){
        ll l = 1, r = n;
        ll pos = -1;
        while(l <= r){
            ll m = l+r>>1;
            if(preA[m] >= preB[i]){
                r = m-1;;
                pos = m;
            }
            else l = m+1;;
        }
        if(pos == -1) continue;
        ans = max(ans,preB[i]-i-pos);
    }
    cout << setprecision(4) << fixed << ans;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("test.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll T = 1;
    // cin >> T;
    for (ll i = 1; i <= T; i++){
        solve();
        cout << '\n';
    }
}

Compilation message

sure.cpp: In function 'void solve()':
sure.cpp:35:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |             ll m = l+r>>1;
      |                    ~^~
sure.cpp:49:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |             ll m = l+r>>1;
      |                    ~^~
sure.cpp: In function 'int main()':
sure.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2584 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2584 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 75 ms 6540 KB Output is correct
18 Correct 81 ms 6484 KB Output is correct
19 Correct 78 ms 6480 KB Output is correct
20 Correct 72 ms 6480 KB Output is correct
21 Correct 75 ms 6524 KB Output is correct
22 Correct 76 ms 6480 KB Output is correct
23 Correct 74 ms 6524 KB Output is correct
24 Correct 74 ms 6484 KB Output is correct
25 Correct 68 ms 6480 KB Output is correct
26 Correct 74 ms 6524 KB Output is correct