結果
問題 | No.1583 Building Blocks |
ユーザー | tenten |
提出日時 | 2021-07-05 18:15:49 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 120 ms / 2,000 ms |
コード長 | 2,119 bytes |
コンパイル時間 | 4,137 ms |
コンパイル使用メモリ | 83,808 KB |
実行使用メモリ | 60,960 KB |
最終ジャッジ日時 | 2024-09-14 02:52:49 |
合計ジャッジ時間 | 8,472 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
50,020 KB |
testcase_01 | AC | 54 ms
50,180 KB |
testcase_02 | AC | 54 ms
49,996 KB |
testcase_03 | AC | 102 ms
53,816 KB |
testcase_04 | AC | 62 ms
50,508 KB |
testcase_05 | AC | 58 ms
50,328 KB |
testcase_06 | AC | 98 ms
53,696 KB |
testcase_07 | AC | 107 ms
54,204 KB |
testcase_08 | AC | 58 ms
49,976 KB |
testcase_09 | AC | 119 ms
56,632 KB |
testcase_10 | AC | 56 ms
49,948 KB |
testcase_11 | AC | 57 ms
50,220 KB |
testcase_12 | AC | 111 ms
54,308 KB |
testcase_13 | AC | 115 ms
56,504 KB |
testcase_14 | AC | 87 ms
51,332 KB |
testcase_15 | AC | 109 ms
53,776 KB |
testcase_16 | AC | 110 ms
56,544 KB |
testcase_17 | AC | 113 ms
56,788 KB |
testcase_18 | AC | 68 ms
50,696 KB |
testcase_19 | AC | 120 ms
60,952 KB |
testcase_20 | AC | 85 ms
51,460 KB |
testcase_21 | AC | 84 ms
51,256 KB |
testcase_22 | AC | 92 ms
51,388 KB |
testcase_23 | AC | 61 ms
50,072 KB |
testcase_24 | AC | 117 ms
56,652 KB |
testcase_25 | AC | 54 ms
49,936 KB |
testcase_26 | AC | 116 ms
56,720 KB |
testcase_27 | AC | 88 ms
51,384 KB |
testcase_28 | AC | 118 ms
56,696 KB |
testcase_29 | AC | 70 ms
50,696 KB |
testcase_30 | AC | 60 ms
50,024 KB |
testcase_31 | AC | 118 ms
56,484 KB |
testcase_32 | AC | 96 ms
53,704 KB |
testcase_33 | AC | 119 ms
60,960 KB |
testcase_34 | AC | 55 ms
50,092 KB |
testcase_35 | AC | 104 ms
53,968 KB |
testcase_36 | AC | 112 ms
56,848 KB |
testcase_37 | AC | 64 ms
50,336 KB |
testcase_38 | AC | 54 ms
50,048 KB |
testcase_39 | AC | 54 ms
50,248 KB |
testcase_40 | AC | 54 ms
50,444 KB |
testcase_41 | AC | 55 ms
50,176 KB |
testcase_42 | AC | 55 ms
50,396 KB |
testcase_43 | AC | 56 ms
49,992 KB |
testcase_44 | AC | 56 ms
50,184 KB |
testcase_45 | AC | 57 ms
50,300 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(); Block[] blocks = new Block[n]; for (int i = 0; i < n; i++) { blocks[i] = new Block(sc.nextInt(), sc.nextInt()); } Arrays.sort(blocks); long[][] dp = new long[n + 1][n + 1]; for (long[] arr : dp) { Arrays.fill(arr, Long.MAX_VALUE / 2); } dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = 0; for (int j = 1; j <= i; j++) { dp[i][j] = Math.min(dp[i][j], dp[i - 1][j]); if (dp[i - 1][j - 1] <= blocks[i - 1].limit) { dp[i][j] = Math.min(dp[i][j], dp[i - 1][j - 1] + blocks[i - 1].weight); } } } for (int i = n; i >= 0; i--) { if (dp[n][i] < Long.MAX_VALUE / 2) { System.out.println(i); return; } } } 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 another) { return - another.weight - another.limit + weight + limit; } public String toString() { return weight + ":" + limit; } } } 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(); } }