結果

問題 No.817 Coin donation
ユーザー betrue12betrue12
提出日時 2019-04-19 21:33:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 452 bytes
コンパイル時間 1,741 ms
コンパイル使用メモリ 167,256 KB
実行使用メモリ 4,404 KB
最終ジャッジ日時 2023-10-23 23:42:47
合計ジャッジ時間 2,703 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 4 ms
4,348 KB
testcase_06 AC 12 ms
4,348 KB
testcase_07 AC 15 ms
4,348 KB
testcase_08 AC 59 ms
4,348 KB
testcase_09 AC 18 ms
4,348 KB
testcase_10 AC 85 ms
4,404 KB
testcase_11 AC 85 ms
4,404 KB
testcase_12 AC 84 ms
4,404 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 <bits/stdc++.h>
using namespace std;

int N, K, A[100000], B[100000];

bool check(int C){
    int64_t sum = 0;
    for(int i=0; i<N; i++) sum += max(0, min(C, B[i]) - A[i] + 1);
    return (sum >= K);
}

int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];

    int ok = 1e9, ng = 0;
    while(ok-ng>1){
        int mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}
0