結果

問題 No.817 Coin donation
ユーザー treeonetreeone
提出日時 2019-04-19 21:46:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 204,476 KB
実行使用メモリ 4,824 KB
最終ジャッジ日時 2023-10-24 01:13:07
合計ジャッジ時間 3,127 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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