結果
| 問題 | No.817 Coin donation | 
| コンテスト | |
| ユーザー |  veqcc | 
| 提出日時 | 2019-04-19 21:42:31 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 29 ms / 2,000 ms | 
| コード長 | 1,089 bytes | 
| コンパイル時間 | 927 ms | 
| コンパイル使用メモリ | 102,488 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-22 17:54:24 | 
| 合計ジャッジ時間 | 1,708 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 14 | 
ソースコード
#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;
}
            
            
            
        