結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー kotatsugamekotatsugame
提出日時 2019-12-19 02:31:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 71,336 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 04:46:34
合計ジャッジ時間 5,281 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 15 ms
4,376 KB
testcase_13 AC 49 ms
4,380 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 16 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 68 ms
4,380 KB
testcase_25 AC 68 ms
4,376 KB
testcase_26 AC 66 ms
4,376 KB
testcase_27 AC 68 ms
4,376 KB
testcase_28 AC 61 ms
4,380 KB
testcase_29 AC 61 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 67 ms
4,380 KB
testcase_36 AC 67 ms
4,380 KB
testcase_37 AC 67 ms
4,380 KB
testcase_38 AC 68 ms
4,380 KB
testcase_39 AC 67 ms
4,380 KB
testcase_40 AC 67 ms
4,380 KB
testcase_41 AC 67 ms
4,376 KB
testcase_42 AC 66 ms
4,380 KB
testcase_43 AC 66 ms
4,380 KB
testcase_44 AC 66 ms
4,376 KB
testcase_45 AC 67 ms
4,376 KB
testcase_46 AC 61 ms
4,376 KB
testcase_47 AC 61 ms
4,376 KB
testcase_48 AC 61 ms
4,376 KB
testcase_49 AC 61 ms
4,376 KB
testcase_50 AC 61 ms
4,376 KB
testcase_51 AC 61 ms
4,376 KB
testcase_52 AC 55 ms
4,380 KB
testcase_53 AC 67 ms
4,376 KB
testcase_54 AC 54 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,K;
pair<int,int>A[5000];
int dp[2][2][5050];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		cin>>A[i].first>>A[i].second;
	}
	sort(A,A+N);
	int now=0;
	for(int i=0;i<2;i++)for(int j=0;j<=K;j++)dp[0][i][j]=-1e9;
	dp[0][0][0]=0;
	for(int i=N;i--;)
	{
		for(int j=0;j<2;j++)for(int k=0;k<=K;k++)dp[1-now][j][k]=dp[now][j][k];
		for(int k=0;k<=K;k++)
		{
			dp[1-now][0][k]=max(dp[1-now][0][k],dp[now][1][k]+A[i].second);
			if(k+A[i].first<=K)dp[1-now][1][k+A[i].first]=max(dp[1-now][1][k+A[i].first],dp[now][0][k]+A[i].second);
		}
		now=1-now;
	}
	int ans=0;
	for(int i=0;i<2;i++)for(int j=0;j<=K;j++)
	{
		ans=max(ans,dp[now][i][j]);
	}
	cout<<ans<<endl;
}
0