結果

問題 No.2093 Shio Ramen
ユーザー ks2mks2m
提出日時 2022-10-07 21:28:52
言語 Java
(openjdk 23)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 2,714 ms
コンパイル使用メモリ 76,060 KB
実行使用メモリ 38,956 KB
最終ジャッジ日時 2024-06-12 06:07:46
合計ジャッジ時間 5,897 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int[] s = new int[n];
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			s[i] = Integer.parseInt(sa[0]);
			a[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		int[] dp = new int[m + 1];
		for (int i = 0; i < n; i++) {
			for (int j = m - s[i]; j >= 0; j--) {
				int nj = j + s[i];
				dp[nj] = Math.max(dp[nj], dp[j] + a[i]);
			}
		}
		System.out.println(dp[m]);
	}
}
0