結果

問題 No.817 Coin donation
ユーザー nao22bnao22b
提出日時 2019-04-19 22:39:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 170,232 KB
実行使用メモリ 5,252 KB
最終ジャッジ日時 2023-10-24 05:50:53
合計ジャッジ時間 2,979 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 4 ms
4,348 KB
testcase_06 AC 14 ms
4,348 KB
testcase_07 AC 17 ms
4,348 KB
testcase_08 AC 65 ms
4,764 KB
testcase_09 AC 20 ms
4,348 KB
testcase_10 AC 95 ms
5,252 KB
testcase_11 AC 95 ms
5,252 KB
testcase_12 AC 94 ms
5,252 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>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)


int main() {
    ll N, K;
    cin >> N >> K;
    ll A[N];
    ll B[N];
    rep(i, N) {
        cin >> A[i];
        cin >> B[i];
        B[i]++;
    }
    sort(A, A + N);
    sort(B, B + N);

    int aidx = 0;
    int bidx = 0;
    ll diff = 0;
    ll last = 0;
    ll count = 0;
    while (true) {
        if (aidx >= N || B[bidx] <= A[aidx]) {
            ll c2 = count + (B[bidx] - last) * diff;
            if (c2 >= K) {
                ll dd = (K - count - 1) / diff;
                ll ans = last + dd;
                cout << ans << endl;
                break;
            }
            count = c2;
            diff--;
            last = B[bidx];
            bidx++;
            if (bidx >= N) {
                break;
            }
        } else {
            ll c2 = count + (A[aidx] - last) * diff;
            if (c2 >= K) {
                ll dd = (K - count - 1) / diff;
                ll ans = last + dd;
                cout << ans << endl;
                break;
            }
            count = c2;
            diff++;
            last = A[aidx];
            aidx++;
        }
    }

    return 0;
}
0