結果

問題 No.817 Coin donation
ユーザー tactac
提出日時 2019-07-10 01:17:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,022 bytes
コンパイル時間 2,664 ms
コンパイル使用メモリ 166,048 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 23:57:48
合計ジャッジ時間 3,376 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,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;
        }
        //out(l << " " << r << " " << mid << " " << cnt);
        if (cnt >= k) r = mid + 1; //rは開区間
        else l = mid;
    }
    out((l + r) / 2);
}
0