結果

問題 No.37 遊園地のアトラクション
コンテスト
ユーザー scache
提出日時 2014-10-09 23:53:13
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 749 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,834 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 43,512 KB
最終ジャッジ日時 2026-04-26 14:39:52
合計ジャッジ時間 5,370 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int n = sc.nextInt();
		int[] c = new int[n];
		int[] v = new int[n];
		for(int i=0;i<n;i++)
			c[i] = sc.nextInt();
		
		for(int i=0;i<n;i++)
			v[i] = sc.nextInt();
		
		solve(t, c, v);
	}

	private void solve(int t, int[] c, int[] v) {
		int[] dp = new int[t+1];
		
		for(int i=0;i<c.length;i++){
			int cur = v[i];
			int count = 1;
			while(cur>0){
				for(int j=dp.length-1;j>=c[i]*count;j--){
					dp[j] = Math.max(dp[j], dp[j-c[i]]+cur);
				}
				cur /= 2;
			}
		}
		
		System.out.println(dp[t]);
	}
}
0