結果

問題 No.817 Coin donation
ユーザー nebukuro09nebukuro09
提出日時 2019-04-19 21:34:21
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 967 ms
コンパイル使用メモリ 107,776 KB
実行使用メモリ 13,564 KB
最終ジャッジ日時 2023-09-04 00:41:18
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 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 15 ms
4,376 KB
testcase_07 AC 19 ms
5,044 KB
testcase_08 AC 74 ms
13,328 KB
testcase_09 AC 23 ms
6,988 KB
testcase_10 AC 108 ms
13,496 KB
testcase_11 AC 109 ms
13,564 KB
testcase_12 AC 108 ms
12,456 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,376 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