結果

問題 No.37 遊園地のアトラクション
ユーザー kou6839
提出日時 2014-12-09 16:19:43
言語 Java
(openjdk 23)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 814 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 77,188 KB
実行使用メモリ 54,492 KB
最終ジャッジ日時 2024-10-10 12:50:40
合計ジャッジ時間 7,870 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;
 
public class Main {
	static int n;
	static int[] c;
	static int[] v;
	static int[] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t=sc.nextInt();
        n = sc.nextInt();
        dp=new int[t+1];
        c=new int[n];
        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();
        }
        for(int i=0;i<n;i++){
        	int cur = v[i];
        	int count=1;
        	while(cur>0){
        		for(int j=t;j>=c[i]*count;j--){
        			dp[j]=Math.max(dp[j],dp[j-c[i]]+cur);
        		}
        		cur/=2;
        		count++;
        	}
        }

    	System.out.println(dp[t]);
    }
}
0