結果

問題 No.54 Happy Hallowe'en
ユーザー cielciel
提出日時 2017-01-19 20:02:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 456 ms / 5,000 ms
コード長 743 bytes
コンパイル時間 4,165 ms
コンパイル使用メモリ 85,416 KB
実行使用メモリ 61,344 KB
最終ジャッジ日時 2023-08-24 17:16:16
合計ジャッジ時間 9,908 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,896 KB
testcase_01 AC 131 ms
55,928 KB
testcase_02 AC 130 ms
55,768 KB
testcase_03 AC 128 ms
55,816 KB
testcase_04 AC 338 ms
59,980 KB
testcase_05 AC 363 ms
60,744 KB
testcase_06 AC 383 ms
61,344 KB
testcase_07 AC 394 ms
60,356 KB
testcase_08 AC 456 ms
60,280 KB
testcase_09 AC 445 ms
60,820 KB
testcase_10 AC 132 ms
55,532 KB
testcase_11 AC 131 ms
55,500 KB
testcase_12 AC 436 ms
60,600 KB
testcase_13 AC 414 ms
60,064 KB
testcase_14 AC 133 ms
56,060 KB
testcase_15 AC 129 ms
55,816 KB
testcase_16 AC 165 ms
56,012 KB
testcase_17 AC 165 ms
56,436 KB
testcase_18 AC 137 ms
55,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.AbstractMap.SimpleEntry;
class Main{
	public static void main(String[]args){
		Scanner cin=new Scanner(System.in);
		int n=cin.nextInt(),vmax=0,tmax=0;
		List<SimpleEntry<Integer,Integer>> v=new ArrayList<>();
		for(int i=0;i<n;i++){
			int a=cin.nextInt(),b=cin.nextInt();
			v.add(new SimpleEntry<>(a,b));
			if(vmax<a)vmax=a;
			if(tmax<b)tmax=b;
		}
		Collections.sort(v,
			(x,y) -> new Integer(x.getKey()+x.getValue()).compareTo(y.getKey()+y.getValue())
		);
		int[] bag=new int[tmax+vmax+1];
		bag[0]=1;
		for(int i=0;i<n;i++){
			for(int j=v.get(i).getValue()-1;j>=0;j--)bag[j+v.get(i).getKey()]|=bag[j];
		}
		for(int i=tmax+vmax;i>=0;i--)if(bag[i]>0){
			System.out.println(i);
			break;
		}
	}
}
0