結果
問題 | No.1570 Blocks |
ユーザー | tenten |
提出日時 | 2021-06-29 08:43:16 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 427 ms / 2,000 ms |
コード長 | 1,595 bytes |
コンパイル時間 | 3,967 ms |
コンパイル使用メモリ | 78,368 KB |
実行使用メモリ | 51,316 KB |
最終ジャッジ日時 | 2024-06-25 17:26:39 |
合計ジャッジ時間 | 16,100 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
37,176 KB |
testcase_01 | AC | 53 ms
37,256 KB |
testcase_02 | AC | 266 ms
46,908 KB |
testcase_03 | AC | 390 ms
50,672 KB |
testcase_04 | AC | 258 ms
45,384 KB |
testcase_05 | AC | 261 ms
46,768 KB |
testcase_06 | AC | 324 ms
49,692 KB |
testcase_07 | AC | 150 ms
41,780 KB |
testcase_08 | AC | 385 ms
50,608 KB |
testcase_09 | AC | 410 ms
50,456 KB |
testcase_10 | AC | 279 ms
47,940 KB |
testcase_11 | AC | 286 ms
47,208 KB |
testcase_12 | AC | 417 ms
51,316 KB |
testcase_13 | AC | 307 ms
49,804 KB |
testcase_14 | AC | 302 ms
47,812 KB |
testcase_15 | AC | 227 ms
45,092 KB |
testcase_16 | AC | 305 ms
49,440 KB |
testcase_17 | AC | 264 ms
44,948 KB |
testcase_18 | AC | 280 ms
48,064 KB |
testcase_19 | AC | 273 ms
44,828 KB |
testcase_20 | AC | 222 ms
44,952 KB |
testcase_21 | AC | 366 ms
49,828 KB |
testcase_22 | AC | 53 ms
36,972 KB |
testcase_23 | AC | 56 ms
36,920 KB |
testcase_24 | AC | 55 ms
36,852 KB |
testcase_25 | AC | 54 ms
37,284 KB |
testcase_26 | AC | 56 ms
37,072 KB |
testcase_27 | AC | 55 ms
37,152 KB |
testcase_28 | AC | 55 ms
37,264 KB |
testcase_29 | AC | 53 ms
37,120 KB |
testcase_30 | AC | 54 ms
37,044 KB |
testcase_31 | AC | 57 ms
37,072 KB |
testcase_32 | AC | 289 ms
49,104 KB |
testcase_33 | AC | 377 ms
47,996 KB |
testcase_34 | AC | 299 ms
49,616 KB |
testcase_35 | AC | 427 ms
51,108 KB |
testcase_36 | AC | 299 ms
49,620 KB |
testcase_37 | AC | 360 ms
47,340 KB |
testcase_38 | AC | 416 ms
50,808 KB |
testcase_39 | AC | 309 ms
49,936 KB |
testcase_40 | AC | 304 ms
49,364 KB |
testcase_41 | AC | 370 ms
47,728 KB |
testcase_42 | AC | 309 ms
49,988 KB |
testcase_43 | AC | 307 ms
49,748 KB |
testcase_44 | AC | 307 ms
49,616 KB |
testcase_45 | AC | 312 ms
49,728 KB |
testcase_46 | AC | 289 ms
49,024 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); PriorityQueue<Block> blocks = new PriorityQueue<>(); for (int i = 0; i < n; i++) { blocks.add(new Block(sc.nextInt(), sc.nextInt())); } long weight = 0; while (blocks.size() > 0) { Block b = blocks.poll(); if (weight > b.limit) { System.out.println("No"); return; } weight += b.weight; } System.out.println("Yes"); } static class Block implements Comparable<Block> { int weight; int limit; public Block(int weight, int limit) { this.weight = weight; this.limit = limit; } public int compareTo(Block b) { return (weight + limit) - (b.limit + b.weight); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }