Submission #1114708

#TimeUsernameProblemLanguageResultExecution timeMemory
1114708hyakupSure Bet (CEOI17_sure)C++17
100 / 100
57 ms3772 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n; scanf("%d", &n);
    vector<double> as, bs;
    for( int i = 1; i <= n; i++ ){
        double a, b; scanf("%lf %lf", &a, &b );
        as.push_back(a);
        bs.push_back(b);
    }
    sort( as.begin(), as.end() );
    sort( bs.begin(), bs.end() );

    double resp = 0, sa = 0, sb = 0;

    for( int i = 1; i <= 2*n; i++ ){
        if( as.empty() || ( !bs.empty() && sa > sb ) ){
            sb += bs.back();
            bs.pop_back();
        }
        else{
            sa += as.back();
            as.pop_back();
        }

        resp = max( resp, min( sa, sb ) - (double)i );
    }
    printf("%.4lf\n", resp );
}

Compilation message (stderr)

sure.cpp: In function 'int main()':
sure.cpp:5:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     int n; scanf("%d", &n);
      |            ~~~~~^~~~~~~~~~
sure.cpp:8:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         double a, b; scanf("%lf %lf", &a, &b );
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...