結果

問題 No.817 Coin donation
ユーザー ks2mks2m
提出日時 2019-04-19 22:54:14
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,161 bytes
コンパイル時間 3,085 ms
コンパイル使用メモリ 79,336 KB
実行使用メモリ 88,876 KB
最終ジャッジ日時 2023-10-24 09:09:19
合計ジャッジ時間 14,390 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,364 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 279 ms
61,712 KB
testcase_06 AC 506 ms
62,636 KB
testcase_07 AC 547 ms
64,380 KB
testcase_08 AC 1,339 ms
81,200 KB
testcase_09 AC 630 ms
62,056 KB
testcase_10 AC 1,524 ms
88,876 KB
testcase_11 AC 1,530 ms
88,736 KB
testcase_12 AC 1,336 ms
88,788 KB
testcase_13 AC 132 ms
57,636 KB
testcase_14 AC 132 ms
57,224 KB
testcase_15 AC 131 ms
57,660 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])) {
				map.put(b[i], map.get(b[i]) - 1);
			} else {
				map.put(b[i], -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