結果

問題 No.817 Coin donation
ユーザー ks2mks2m
提出日時 2019-04-19 23:02:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,388 ms / 2,000 ms
コード長 1,177 bytes
コンパイル時間 2,468 ms
コンパイル使用メモリ 79,472 KB
実行使用メモリ 88,956 KB
最終ジャッジ日時 2023-10-24 10:46:25
合計ジャッジ時間 12,123 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,452 KB
testcase_01 AC 136 ms
57,752 KB
testcase_02 AC 147 ms
57,752 KB
testcase_03 AC 172 ms
57,564 KB
testcase_04 AC 141 ms
57,568 KB
testcase_05 AC 281 ms
62,240 KB
testcase_06 AC 508 ms
62,436 KB
testcase_07 AC 549 ms
64,480 KB
testcase_08 AC 1,206 ms
80,224 KB
testcase_09 AC 593 ms
62,084 KB
testcase_10 AC 1,338 ms
88,232 KB
testcase_11 AC 1,387 ms
88,956 KB
testcase_12 AC 1,388 ms
88,572 KB
testcase_13 AC 134 ms
57,432 KB
testcase_14 AC 135 ms
57,448 KB
testcase_15 AC 134 ms
57,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		sc.close();

		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for (int i = 0; i < n; i++) {
			if (map.containsKey(a[i])) {
				map.put(a[i], map.get(a[i]) + 1);
			} else {
				map.put(a[i], 1);
			}
			if (map.containsKey(b[i] + 1)) {
				map.put(b[i] + 1, map.get(b[i] + 1) - 1);
			} else {
				map.put(b[i] + 1, -1);
			}
		}

		int prev = 0;
		for (int key : map.keySet()) {
			prev = map.get(key) + prev;
			map.put(key, prev);
		}

		int prevK = map.firstKey();
		long prevV = map.get(prevK);
		map.pollFirstEntry();
		long cnt = 0;
		for (int key : map.keySet()) {
			if (cnt + prevV * (key - prevK) >= k) {
				long x = (k - 1 - cnt) / prevV + prevK;
				System.out.println(x);
				break;
			} else {
				cnt += prevV * (key - prevK);
				prevK = key;
				prevV = map.get(prevK);
			}
		}
	}
}
0