結果

問題 No.817 Coin donation
ユーザー veqccveqcc
提出日時 2019-04-19 21:42:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 102,608 KB
実行使用メモリ 5,196 KB
最終ジャッジ日時 2023-10-24 00:53:30
合計ジャッジ時間 1,754 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 20 ms
4,716 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 29 ms
5,196 KB
testcase_11 AC 29 ms
5,196 KB
testcase_12 AC 29 ms
5,196 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 <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

ll n, k;
ll A[100005], B[100005];

// 金額がiのコインはk番目未満か
bool check(ll i) {
    ll cnt = 0;
    for (int j = 0; j < n; j++) {
        if (i >= A[j]) {
            if (i <= B[j]) {
                cnt += i - A[j] + 1;
            } else {
                cnt += B[j] - A[j] + 1;
            }
        }
    }

    if (cnt < k) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i ++) {
        cin >> A[i] >> B[i];
    }

    ll l = 0, r = 1e9;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        if (check(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }

    cout << r << "\n";
    return 0;
}
0