結果

問題 No.1715 Dinner 2
ユーザー ktr216ktr216
提出日時 2021-10-22 21:38:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 743 bytes
コンパイル時間 1,831 ms
コンパイル使用メモリ 175,700 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 12:37:30
合計ジャッジ時間 2,969 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 WA -
testcase_14 AC 3 ms
4,348 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,348 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,348 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
4,348 KB
testcase_32 WA -
testcase_33 AC 3 ms
4,348 KB
testcase_34 WA -
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;

typedef long long ll;

int main() {
    int N, D;
    cin >> N >> D;
    vector<int> P(N), Q(N);
    vector<pair<int, int>> A, B;
    rep(i, 0, N) {
        cin >> P[i] >> Q[i];
        if (P[i] < Q[i]) A.push_back(make_pair(P[i], Q[i]));
        else B.push_back(make_pair(P[i], Q[i]));
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    ll ans = 0, x = 0;
    rep(i, 0, A.size()) {
        x -= A[i].first;
        ans = min(ans, x);
        x += A[i].second;
    }
    for (int i = B.size() - 1; i >= 0; i--) {
        x -= B[i].first;
        ans = min(ans, x);
        x += B[i].second;
    }
    cout << ans << endl;
}
0