結果

問題 No.817 Coin donation
ユーザー tentententen
提出日時 2020-12-04 12:57:32
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,297 bytes
コンパイル時間 4,010 ms
コンパイル使用メモリ 75,772 KB
実行使用メモリ 81,632 KB
最終ジャッジ日時 2023-10-13 01:01:47
合計ジャッジ時間 12,749 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,844 KB
testcase_01 AC 124 ms
56,008 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 262 ms
60,416 KB
testcase_06 AC 507 ms
61,152 KB
testcase_07 AC 530 ms
63,092 KB
testcase_08 AC 1,181 ms
73,756 KB
testcase_09 AC 565 ms
60,480 KB
testcase_10 AC 1,432 ms
81,632 KB
testcase_11 AC 1,393 ms
81,300 KB
testcase_12 AC 1,400 ms
80,700 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 117 ms
56,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        TreeMap<Integer, Integer> map = new TreeMap<>();
        int[] aArr = new int[n];
        int[] bArr = new int[n];
        for (int i = 0; i < n; i++) {
            aArr[i] = sc.nextInt();
            bArr[i] = sc.nextInt() + 1;
            map.put(aArr[i], 0);
            map.put(bArr[i], 0);
        }
        int idx = 0;
        for (int x : map.keySet()) {
            map.put(x, idx);
            idx++;
        }
        int[] imos = new int[idx];
        for (int i = 0; i < n; i++) {
            imos[map.get(aArr[i])]++;
            imos[map.get(bArr[i])]--;
        }
        for (int i = 1; i < idx; i++) {
            imos[i] += imos[i - 1];
        }
        for (int x : map.keySet()) {
            if (map.get(x) == idx - 1) {
                break;
            }
            int next = map.higherKey(x);
            int count = imos[map.get(x)];
            long size = next - x;
            if (k > size * count) {
                k -= size * count;
            } else {
                System.out.println(x + k / count);
                return;
            }
        }
    }
}
0