結果

問題 No.817 Coin donation
ユーザー TiramisterTiramister
提出日時 2019-04-19 22:39:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 580 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 69,368 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 05:50:55
合計ジャッジ時間 1,769 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
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 AC 4 ms
4,348 KB
testcase_06 AC 13 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 59 ms
4,348 KB
testcase_09 AC 19 ms
4,348 KB
testcase_10 AC 84 ms
4,348 KB
testcase_11 AC 85 ms
4,348 KB
testcase_12 AC 84 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using lint = long long;

int main() {
    lint N, K;
    std::cin >> N >> K;

    std::vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i] >> B[i];
    }

    int ng = 0, ok = 1e9 + 1;
    // ok以下の硬貨がK枚以上
    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;
        lint cnt = 0;
        for (int i = 0; i < N; ++i) {
            cnt += std::max(0, std::min(B[i], mid) - A[i] + 1);
        }

        (cnt >= K ? ok : ng) = mid;
    }

    std::cout << ok << std::endl;
    return 0;
}
0