結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー 37zigen37zigen
提出日時 2019-12-15 01:43:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,047 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 4,563 ms
コンパイル使用メモリ 76,436 KB
実行使用メモリ 256,228 KB
最終ジャッジ日時 2023-09-10 19:22:03
合計ジャッジ時間 36,199 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
55,828 KB
testcase_01 AC 133 ms
55,728 KB
testcase_02 AC 141 ms
55,752 KB
testcase_03 AC 133 ms
55,780 KB
testcase_04 AC 134 ms
53,800 KB
testcase_05 AC 144 ms
56,048 KB
testcase_06 AC 140 ms
56,200 KB
testcase_07 AC 136 ms
55,976 KB
testcase_08 AC 144 ms
55,656 KB
testcase_09 AC 264 ms
61,296 KB
testcase_10 AC 180 ms
60,804 KB
testcase_11 AC 236 ms
61,372 KB
testcase_12 AC 434 ms
95,376 KB
testcase_13 AC 776 ms
235,264 KB
testcase_14 AC 318 ms
76,420 KB
testcase_15 AC 331 ms
83,040 KB
testcase_16 AC 452 ms
91,084 KB
testcase_17 AC 485 ms
120,720 KB
testcase_18 AC 132 ms
56,124 KB
testcase_19 AC 134 ms
55,476 KB
testcase_20 AC 132 ms
55,664 KB
testcase_21 AC 180 ms
60,272 KB
testcase_22 AC 176 ms
58,368 KB
testcase_23 AC 175 ms
58,232 KB
testcase_24 AC 825 ms
254,832 KB
testcase_25 AC 860 ms
252,288 KB
testcase_26 AC 872 ms
256,228 KB
testcase_27 AC 908 ms
255,940 KB
testcase_28 AC 1,017 ms
255,772 KB
testcase_29 AC 1,016 ms
254,112 KB
testcase_30 AC 135 ms
55,776 KB
testcase_31 AC 130 ms
55,916 KB
testcase_32 AC 170 ms
58,132 KB
testcase_33 AC 174 ms
58,272 KB
testcase_34 AC 181 ms
60,648 KB
testcase_35 AC 831 ms
252,332 KB
testcase_36 AC 777 ms
252,160 KB
testcase_37 AC 859 ms
252,592 KB
testcase_38 AC 786 ms
254,620 KB
testcase_39 AC 878 ms
250,792 KB
testcase_40 AC 901 ms
253,156 KB
testcase_41 AC 857 ms
252,368 KB
testcase_42 AC 906 ms
253,144 KB
testcase_43 AC 910 ms
249,912 KB
testcase_44 AC 883 ms
252,612 KB
testcase_45 AC 903 ms
252,596 KB
testcase_46 AC 1,047 ms
254,544 KB
testcase_47 AC 992 ms
252,328 KB
testcase_48 AC 996 ms
254,480 KB
testcase_49 AC 1,028 ms
254,212 KB
testcase_50 AC 1,003 ms
253,008 KB
testcase_51 AC 998 ms
252,080 KB
testcase_52 AC 771 ms
229,884 KB
testcase_53 AC 839 ms
252,572 KB
testcase_54 AC 799 ms
254,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int[][] a=new int[N+1][2];
		for(int i=0;i<N;++i){
			a[i][0]=sc.nextInt();
			a[i][1]=sc.nextInt();
		}
		Arrays.sort(a,new Comparator<int[]>(){
			public int compare(int[] a,int[] b){
				if(a[0]!=b[0])
					return Integer.compare(a[0],b[0]);
				else
					return Integer.compare(a[1],b[1]);
			}
		});
		++N;
		int[][] dp=new int[K+1][N];
		for(int i=0;i<=K;++i){
			for(int j=0;j<N;++j){
				dp[i][j]=-Integer.MAX_VALUE/3;
			}
		}
		int[][] seg=new int[K+1][N+10];
		for(int i=0;i<=K;++i){
			for(int j=0;j<N;++j){
				dp[i][j]=Math.max((i>0?dp[i-1][j]:0),(j>0?dp[i][j-1]:0));
				if(i-a[j][0]>=0){
					dp[i][j]=Math.max(dp[i][j],a[j][1]+(j>0?seg[i-a[j][0]][j-1]:0));
				}
				if(j+1<N)
					seg[i][j+1]=Math.max(seg[i][j+1],dp[i][j]+a[j+1][1]);
					seg[i][j+1]=Math.max(seg[i][j+1],seg[i][j]);
			}
		}
		System.out.println(dp[K][N-1]);
	}
}
	
0