結果

問題 No.1570 Blocks
ユーザー tentententen
提出日時 2021-06-29 08:43:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 1,595 bytes
コンパイル時間 5,192 ms
コンパイル使用メモリ 74,676 KB
実行使用メモリ 62,420 KB
最終ジャッジ日時 2023-09-08 00:10:09
合計ジャッジ時間 14,404 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,568 KB
testcase_01 AC 40 ms
49,608 KB
testcase_02 AC 231 ms
57,296 KB
testcase_03 AC 343 ms
61,996 KB
testcase_04 AC 212 ms
55,716 KB
testcase_05 AC 214 ms
57,088 KB
testcase_06 AC 278 ms
56,868 KB
testcase_07 AC 120 ms
55,024 KB
testcase_08 AC 333 ms
62,188 KB
testcase_09 AC 356 ms
62,076 KB
testcase_10 AC 238 ms
55,888 KB
testcase_11 AC 249 ms
58,752 KB
testcase_12 AC 348 ms
62,252 KB
testcase_13 AC 249 ms
60,516 KB
testcase_14 AC 266 ms
61,384 KB
testcase_15 AC 196 ms
56,116 KB
testcase_16 AC 262 ms
61,332 KB
testcase_17 AC 227 ms
56,348 KB
testcase_18 AC 247 ms
57,796 KB
testcase_19 AC 236 ms
57,544 KB
testcase_20 AC 191 ms
56,020 KB
testcase_21 AC 327 ms
59,100 KB
testcase_22 AC 42 ms
49,504 KB
testcase_23 AC 43 ms
49,572 KB
testcase_24 AC 46 ms
49,700 KB
testcase_25 AC 42 ms
49,820 KB
testcase_26 AC 46 ms
49,736 KB
testcase_27 AC 48 ms
49,652 KB
testcase_28 AC 45 ms
49,732 KB
testcase_29 AC 45 ms
49,608 KB
testcase_30 AC 42 ms
49,452 KB
testcase_31 AC 46 ms
49,800 KB
testcase_32 AC 254 ms
60,480 KB
testcase_33 AC 323 ms
58,524 KB
testcase_34 AC 265 ms
61,232 KB
testcase_35 AC 358 ms
62,188 KB
testcase_36 AC 264 ms
61,240 KB
testcase_37 AC 315 ms
61,988 KB
testcase_38 AC 363 ms
61,952 KB
testcase_39 AC 270 ms
61,524 KB
testcase_40 AC 265 ms
60,892 KB
testcase_41 AC 370 ms
62,420 KB
testcase_42 AC 266 ms
61,516 KB
testcase_43 AC 260 ms
59,292 KB
testcase_44 AC 264 ms
61,632 KB
testcase_45 AC 267 ms
61,404 KB
testcase_46 AC 259 ms
60,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0