Submission #1027369

#TimeUsernameProblemLanguageResultExecution timeMemory
1027369vjudge1Sure Bet (CEOI17_sure)C++17
100 / 100
53 ms1980 KiB
#include <stdio.h>
#include <algorithm>
#include <vector>

int main() {
    int n;
    scanf("%d", &n);
    std::vector<double> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        scanf("%lf %lf", &a[i], &b[i]);
        a[i] -= 1;
        b[i] -= 1;
    }

    std::sort(a.begin(), a.end());
    std::reverse(a.begin(), a.end());
    std::sort(b.begin(), b.end());
    std::reverse(b.begin(), b.end());

    int i = 0, j = 0;
    double res = 0, sa = 0, sb = 0;
    while (i < n) {
        sa += a[i];
        ++i;
        while ((j < n) && (std::min(sa - j, sb - i) < std::min(sa - j - 1, sb + b[j] - i))) {
            sb += b[j];
            ++j;
        }
        res = std::max(res, std::min(sa - j, sb - i));
    }

    printf("%.4lf\n", res);
    return 0;
}

Compilation message (stderr)

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