結果

問題 No.817 Coin donation
ユーザー merom686merom686
提出日時 2019-04-19 21:51:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 76,104 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 01:32:45
合計ジャッジ時間 1,671 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_06 AC 6 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 21 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 30 ms
4,348 KB
testcase_11 AC 30 ms
4,348 KB
testcase_12 AC 30 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>
#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