제출 #854643

#제출 시각아이디문제언어결과실행 시간메모리
854643anhphantSure Bet (CEOI17_sure)C++14
100 / 100
94 ms8452 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ldb;
#define endl '\n'

ll N;
ldb A[100007], B[100007];

void initialize() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen("FILE.INP", "r")) {
        freopen("FILE.INP", "r", stdin);
        freopen("FILE.OUT", "w", stdout);
    }

    cin >> N;
    for(int i = 1; i <= N; ++i) cin >> A[i] >> B[i];

    sort(A + 1, A + 1 + N, greater<ldb>());
    sort(B + 1, B + 1 + N, greater<ldb>());

    /*for(int i = 1; i <= N; ++i) {
        cerr << A[i] << " " << B[i] << endl;
    }*/
}

namespace subtask2 {
    void solve() {
        ldb sum1 = 0;
        ldb ans = 0;
        for(int i = 0; i <= N; ++i) {
            sum1 += A[i];
            ldb sum2 = 0;
            for(int j = 0; j <= N; ++j) {
                sum2 += B[j];
                ans = max(ans, min(sum1 - ldb(i + j), sum2 - ldb(i + j)));

                //cerr << i << " " << j << " " << i + j << endl;
                //cerr << setprecision(4) << sum1 << " " << sum2 << " " <<
                //sum1 - ldb(i + j) << " " << sum2 - ldb(i + j) << endl;
            }
        }

        cout << fixed << setprecision(4) << ans;
    }

    void process() {
        solve();
    }
}

namespace subtask3 {
    ldb Apre[100007], Bpre[100007];
    void solve() {
        for(int i = 1; i <= N; ++i) {
            Apre[i] = Apre[i - 1] + A[i];
            Bpre[i] = Bpre[i - 1] + B[i];
        }

        ldb ans = 0;

        for(int i = 1; i <= N; ++i) {
            int j;
            j = lower_bound(Bpre + 1, Bpre + 1 + N, Apre[i]) - Bpre;
            if (j != N + 1) ans = max(ans, Apre[i] - ldb(i + j));

            j = lower_bound(Apre + 1, Apre + 1 + N, Bpre[i]) - Apre;
            if (j != N + 1) ans = max(ans, Bpre[i] - ldb(i + j));
        }

        cout << fixed << setprecision(4) << ans;
    }

    void process() {
        solve();
    }
}

int main() {
    initialize();
    subtask3 :: process();
}

컴파일 시 표준 에러 (stderr) 메시지

sure.cpp: In function 'void initialize()':
sure.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen("FILE.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen("FILE.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...