結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー 37zigen37zigen
提出日時 2019-12-15 01:40:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,071 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 2,836 ms
コンパイル使用メモリ 75,840 KB
実行使用メモリ 356,400 KB
最終ジャッジ日時 2023-09-10 19:18:11
合計ジャッジ時間 36,024 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,756 KB
testcase_01 AC 120 ms
56,068 KB
testcase_02 AC 128 ms
56,716 KB
testcase_03 AC 122 ms
55,824 KB
testcase_04 AC 124 ms
55,620 KB
testcase_05 AC 121 ms
55,900 KB
testcase_06 AC 128 ms
55,980 KB
testcase_07 AC 128 ms
56,816 KB
testcase_08 AC 132 ms
55,816 KB
testcase_09 AC 266 ms
66,496 KB
testcase_10 AC 173 ms
61,024 KB
testcase_11 AC 238 ms
61,744 KB
testcase_12 AC 375 ms
125,892 KB
testcase_13 AC 783 ms
262,084 KB
testcase_14 AC 315 ms
88,504 KB
testcase_15 AC 336 ms
106,980 KB
testcase_16 AC 477 ms
118,404 KB
testcase_17 AC 508 ms
137,460 KB
testcase_18 AC 122 ms
55,908 KB
testcase_19 AC 130 ms
55,820 KB
testcase_20 AC 129 ms
55,664 KB
testcase_21 AC 185 ms
60,616 KB
testcase_22 AC 178 ms
58,240 KB
testcase_23 AC 181 ms
58,200 KB
testcase_24 AC 962 ms
354,348 KB
testcase_25 AC 943 ms
355,084 KB
testcase_26 AC 962 ms
354,460 KB
testcase_27 AC 965 ms
354,840 KB
testcase_28 AC 1,044 ms
354,396 KB
testcase_29 AC 1,043 ms
354,064 KB
testcase_30 AC 120 ms
55,832 KB
testcase_31 AC 120 ms
53,928 KB
testcase_32 AC 155 ms
58,200 KB
testcase_33 AC 159 ms
60,608 KB
testcase_34 AC 178 ms
60,616 KB
testcase_35 AC 940 ms
354,468 KB
testcase_36 AC 930 ms
354,224 KB
testcase_37 AC 929 ms
354,216 KB
testcase_38 AC 936 ms
354,600 KB
testcase_39 AC 932 ms
354,680 KB
testcase_40 AC 965 ms
354,664 KB
testcase_41 AC 964 ms
354,508 KB
testcase_42 AC 979 ms
354,148 KB
testcase_43 AC 965 ms
354,344 KB
testcase_44 AC 973 ms
354,772 KB
testcase_45 AC 985 ms
354,596 KB
testcase_46 AC 1,062 ms
354,376 KB
testcase_47 AC 1,043 ms
355,100 KB
testcase_48 AC 1,071 ms
356,400 KB
testcase_49 AC 1,047 ms
354,888 KB
testcase_50 AC 1,024 ms
354,848 KB
testcase_51 AC 1,067 ms
352,304 KB
testcase_52 AC 856 ms
355,952 KB
testcase_53 AC 933 ms
354,140 KB
testcase_54 AC 861 ms
353,968 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[] P=new int[N+1];
		int[] D=new int[N+1];
		int[][] a=new int[N+1][2];
		for(int i=0;i<N;++i){
			P[i]=sc.nextInt();
			D[i]=sc.nextInt();
		}
		P[N]=0;
		D[N]=0;
		for(int i=0;i<=N;++i){
			a[i][0]=P[i];
			a[i][1]=D[i];
		}
		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];
		int[][] ma=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;
				ma[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));
				ma[i][j]=Math.max((i>0?ma[i-1][j]:0),(j>0?ma[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