結果

問題 No.860 買い物
ユーザー kyuridenamidakyuridenamida
提出日時 2019-09-10 23:54:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,191 bytes
コンパイル時間 3,113 ms
コンパイル使用メモリ 209,204 KB
実行使用メモリ 9,980 KB
最終ジャッジ日時 2023-09-15 13:21:01
合計ジャッジ時間 5,301 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 66 ms
4,592 KB
testcase_12 AC 67 ms
4,592 KB
testcase_13 AC 96 ms
7,980 KB
testcase_14 AC 108 ms
6,816 KB
testcase_15 AC 38 ms
4,512 KB
testcase_16 WA -
testcase_17 AC 92 ms
4,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
static const long long INF = 1e18;

int main() {
    size_t N;
    cin >> N;
    vector<long long> C(N), D(N);
    for (int i = 0; i < N; i++) cin >> C[i] >> D[i];

    auto get_min = [&](int l, int r) {
        return *min_element(C.begin() + l, C.begin() + r);
    };

    deque<pair<long long, long long> > Q;
    multiset<long long> X;
    auto add_back = [&](long long a, long long b) {
        Q.emplace_back(a, b);
        X.insert(a + b);
    };
    auto add_front = [&](long long a, long long b) {
        Q.emplace_front(a, b);
        X.insert(a + b);
    };
    auto upd = [&](long long c) {
        long long v = -INF;
        while (!Q.empty() && Q.front().second <= c) {
            v = max(Q.front().first, v);
            X.erase(X.find(Q.front().first + Q.front().second));
            Q.pop_front();
        }
        if (v != -INF) {
            add_front(v, c);
        }
    };
    add_back(D[0], -C[0]);
    for (int i = 1; i < N; i++) {
        add_back(*X.rbegin() + D[i], -C[i]);
        upd(-C[i]);
    }
    cout << accumulate(C.begin(), C.end(), 0ll) + accumulate(D.begin(), D.end(), 0ll) - *X.rbegin() << endl;


}
0