結果

問題 No.817 Coin donation
ユーザー tactac
提出日時 2019-07-10 01:31:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 167,648 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 00:25:29
合計ジャッジ時間 2,921 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 13 ms
4,376 KB
testcase_07 AC 15 ms
4,380 KB
testcase_08 AC 60 ms
4,376 KB
testcase_09 AC 18 ms
4,380 KB
testcase_10 AC 84 ms
4,380 KB
testcase_11 AC 84 ms
4,376 KB
testcase_12 AC 85 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 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 + 1;
    int c = 0;
    while (c++ < 100) {
        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 + 1; //rは開区間
        else l = mid;
    }
    out((l + r) / 2);
}
0