結果

問題 No.817 Coin donation
ユーザー treeonetreeone
提出日時 2019-04-19 21:46:29
言語 C++17
(gcc 12.2.0 + boost 1.81.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 1,939 ms
実行使用メモリ 9,716 KB
最終ジャッジ日時 2023-03-31 13:37:03
合計ジャッジ時間 3,334 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,656 KB
testcase_01 AC 1 ms
9,696 KB
testcase_02 AC 2 ms
7,656 KB
testcase_03 AC 1 ms
7,584 KB
testcase_04 AC 1 ms
9,716 KB
testcase_05 AC 2 ms
7,608 KB
testcase_06 AC 5 ms
9,712 KB
testcase_07 AC 6 ms
9,668 KB
testcase_08 AC 19 ms
7,584 KB
testcase_09 AC 7 ms
9,624 KB
testcase_10 AC 28 ms
7,580 KB
testcase_11 AC 28 ms
7,592 KB
testcase_12 AC 28 ms
7,608 KB
testcase_13 AC 1 ms
7,676 KB
testcase_14 AC 2 ms
7,684 KB
testcase_15 AC 1 ms
7,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, k;
vector<int> a, b;

bool f(int mid){
    int sum = 0;
    rep(i, 0, n){
        if(a[i] <= mid && mid <= b[i]){
            sum += mid - a[i] + 1;
        }else if(b[i] < mid){
            sum += b[i] - a[i] + 1;
        }
    }
    return sum >= k;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    a.resize(n); b.resize(n);
    rep(i, 0, n){
        cin >> a[i] >> b[i];
    }
    int ok = *max_element(b.begin(), b.end());
    int ng = 0;
    while(ok - ng > 1){
        int mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}
0