結果

問題 No.817 Coin donation
ユーザー tactac
提出日時 2019-07-10 01:33:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 169,008 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 00:26:04
合計ジャッジ時間 2,745 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 4 ms
4,384 KB
testcase_06 AC 11 ms
4,376 KB
testcase_07 AC 15 ms
4,376 KB
testcase_08 AC 53 ms
4,380 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 77 ms
4,376 KB
testcase_11 AC 77 ms
4,376 KB
testcase_12 AC 77 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int n, k; cin >> n >> k;
    vector<pii> v;
    int rmax = -inf;
    rep(i, n) {
        int a, b; cin >> a >> b;
        v.eb(a, b);
        chmax(rmax, b);
    }
    int l = 1, r = rmax; //l, r閉区間
    while (1) {
        int mid = (l + r) / 2;
        int cnt = 0;
        rep(i, n) {
            if (mid - v[i].F < 0) continue;
            cnt += min(v[i].S, mid) - v[i].F + 1;
            if (cnt >= k) break;
        }
        //out(l << " " << r << " " << mid << " " << cnt);
        if (cnt >= k) r = mid;
        else l = mid;
        if (l + 1 == r) {
            out(r);
            return 0;
        }
    }
    
}
0