結果
問題 | No.817 Coin donation |
ユーザー |
![]() |
提出日時 | 2019-04-19 23:02:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,411 ms / 2,000 ms |
コード長 | 1,177 bytes |
コンパイル時間 | 2,250 ms |
コンパイル使用メモリ | 80,024 KB |
実行使用メモリ | 74,260 KB |
最終ジャッジ日時 | 2024-09-23 03:09:28 |
合計ジャッジ時間 | 11,623 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 14 |
ソースコード
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); } } } }