結果

問題 No.54 Happy Hallowe'en
ユーザー ぴろずぴろず
提出日時 2015-10-05 11:14:09
言語 Java19
(openjdk 21)
結果
AC  
実行時間 490 ms / 5,000 ms
コード長 792 bytes
コンパイル時間 3,659 ms
コンパイル使用メモリ 77,280 KB
実行使用メモリ 60,628 KB
最終ジャッジ日時 2023-08-05 20:08:42
合計ジャッジ時間 8,606 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,656 KB
testcase_01 AC 126 ms
55,668 KB
testcase_02 AC 127 ms
55,884 KB
testcase_03 AC 127 ms
56,116 KB
testcase_04 AC 305 ms
60,236 KB
testcase_05 AC 331 ms
57,888 KB
testcase_06 AC 363 ms
59,948 KB
testcase_07 AC 374 ms
60,044 KB
testcase_08 AC 450 ms
60,184 KB
testcase_09 AC 490 ms
60,628 KB
testcase_10 AC 129 ms
55,940 KB
testcase_11 AC 128 ms
55,884 KB
testcase_12 AC 371 ms
60,592 KB
testcase_13 AC 380 ms
59,928 KB
testcase_14 AC 127 ms
55,672 KB
testcase_15 AC 124 ms
53,752 KB
testcase_16 AC 139 ms
56,640 KB
testcase_17 AC 143 ms
55,456 KB
testcase_18 AC 131 ms
55,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static int MAX = 20000;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		House[] h = new House[n];
		for(int i=0;i<n;i++) {
			int v = sc.nextInt();
			int t = sc.nextInt();
			h[i] = new House(v,t);
		}
		Arrays.sort(h,(a,b)->Integer.compare(a.v + a.t, b.v + b.t));
		boolean[] dp = new boolean[MAX+1];
		dp[0] = true;
		for(int i=0;i<n;i++) {
			for(int j=h[i].t-1;j>=0;j--) {
				if (dp[j]) {
					dp[j+h[i].v] = true;
				}
			}
		}
		int max = 0;
		for(int i=0;i<=MAX;i++) {
			if (dp[i]) {
				max = i;
			}
		}
		System.out.println(max);
	}

	static class House {
		int v,t;
		public House(int v,int t) {
			this.v = v;
			this.t = t;
		}
	}

}
0