結果

問題 No.817 Coin donation
ユーザー nebukuro09nebukuro09
提出日時 2019-04-19 21:34:21
言語 D
(dmd 2.099.1)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 3,159 ms
使用メモリ 13,196 KB
最終ジャッジ日時 2022-11-22 06:33:54
合計ジャッジ時間 2,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,324 KB
testcase_01 AC 1 ms
3,304 KB
testcase_02 AC 2 ms
3,344 KB
testcase_03 AC 1 ms
3,312 KB
testcase_04 AC 2 ms
3,288 KB
testcase_05 AC 5 ms
3,872 KB
testcase_06 AC 16 ms
4,624 KB
testcase_07 AC 20 ms
5,672 KB
testcase_08 AC 80 ms
12,624 KB
testcase_09 AC 24 ms
6,508 KB
testcase_10 AC 118 ms
13,112 KB
testcase_11 AC 116 ms
13,176 KB
testcase_12 AC 114 ms
13,196 KB
testcase_13 AC 2 ms
3,236 KB
testcase_14 AC 1 ms
3,304 KB
testcase_15 AC 2 ms
3,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long;
    auto AB = N.iota.map!(_ => readln.split.map!(to!long).array).array;

    bool check(long x) {
        long tmp = 0;
        foreach (ab; AB) {
            if (ab[1] <= x) {
                tmp += ab[1] - ab[0] + 1;
            } else if (ab[0] <= x) {
                tmp += x - ab[0] + 1;
            }
        }
        return tmp >= K;
    }

    long hi = 10L^^9;
    long lo = 0;

    while (hi - lo > 1) {
        long mid = (hi + lo) / 2;
        (check(mid) ? hi : lo) = mid;
    }

    hi.writeln;
}
0