結果

問題 No.817 Coin donation
ユーザー merom686merom686
提出日時 2019-04-19 21:51:12
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 528 ms
使用メモリ 5,160 KB
最終ジャッジ日時 2022-11-22 08:47:54
合計ジャッジ時間 1,798 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
4,904 KB
testcase_01 AC 1 ms
5,156 KB
testcase_02 AC 1 ms
4,904 KB
testcase_03 AC 1 ms
4,900 KB
testcase_04 AC 1 ms
4,900 KB
testcase_05 AC 2 ms
4,900 KB
testcase_06 AC 5 ms
4,908 KB
testcase_07 AC 6 ms
4,900 KB
testcase_08 AC 18 ms
4,900 KB
testcase_09 AC 7 ms
4,904 KB
testcase_10 AC 26 ms
5,160 KB
testcase_11 AC 26 ms
5,160 KB
testcase_12 AC 26 ms
4,908 KB
testcase_13 AC 1 ms
4,904 KB
testcase_14 AC 1 ms
4,904 KB
testcase_15 AC 2 ms
4,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class F>
int lower_bound(int i0, int i1, F f) {
    while (i0 < i1) {
        int i = (i0 + i1) / 2;
        if (f(i)) i1 = i; else i0 = i + 1;
    }
    return i0;
}

struct P {
    int a, b;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        p[i] = { a, b + 1 };
    }

    //c円以下のものがk枚あるか 満たす中で最も小さいもの
    int c = lower_bound(1, 1 << 30, [&](int c) {
        ll s = 0;
        for (int i = 0; i < n; i++) {
            if (c < p[i].a) continue;
            if (c < p[i].b) s += c + 1 - p[i].a; else s += p[i].b - p[i].a;
        }
        return s >= (ll)k;
    });

    cout << c << endl;

    return 0;
}
0