結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー chocoruskchocorusk
提出日時 2019-12-14 00:09:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 1,334 ms
コンパイル使用メモリ 115,648 KB
実行使用メモリ 201,904 KB
最終ジャッジ日時 2023-09-10 07:24:53
合計ジャッジ時間 7,968 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,648 KB
testcase_01 AC 2 ms
5,416 KB
testcase_02 AC 2 ms
5,500 KB
testcase_03 AC 2 ms
5,476 KB
testcase_04 AC 2 ms
5,420 KB
testcase_05 AC 2 ms
5,556 KB
testcase_06 AC 2 ms
5,540 KB
testcase_07 AC 2 ms
5,580 KB
testcase_08 AC 2 ms
5,524 KB
testcase_09 AC 7 ms
18,880 KB
testcase_10 AC 5 ms
12,768 KB
testcase_11 AC 7 ms
20,520 KB
testcase_12 AC 30 ms
50,444 KB
testcase_13 AC 132 ms
181,912 KB
testcase_14 AC 19 ms
34,048 KB
testcase_15 AC 20 ms
43,956 KB
testcase_16 AC 32 ms
80,976 KB
testcase_17 AC 65 ms
125,456 KB
testcase_18 AC 2 ms
5,420 KB
testcase_19 AC 2 ms
5,428 KB
testcase_20 AC 2 ms
5,492 KB
testcase_21 AC 4 ms
9,108 KB
testcase_22 AC 3 ms
8,296 KB
testcase_23 AC 4 ms
8,592 KB
testcase_24 AC 175 ms
201,696 KB
testcase_25 AC 157 ms
201,652 KB
testcase_26 AC 154 ms
201,656 KB
testcase_27 AC 153 ms
201,644 KB
testcase_28 AC 143 ms
201,656 KB
testcase_29 AC 144 ms
201,744 KB
testcase_30 AC 2 ms
5,444 KB
testcase_31 AC 2 ms
5,420 KB
testcase_32 AC 4 ms
8,388 KB
testcase_33 AC 4 ms
8,756 KB
testcase_34 AC 5 ms
9,500 KB
testcase_35 AC 154 ms
201,700 KB
testcase_36 AC 155 ms
201,648 KB
testcase_37 AC 158 ms
201,628 KB
testcase_38 AC 159 ms
201,700 KB
testcase_39 AC 159 ms
201,716 KB
testcase_40 AC 155 ms
201,708 KB
testcase_41 AC 154 ms
201,644 KB
testcase_42 AC 154 ms
201,832 KB
testcase_43 AC 153 ms
201,904 KB
testcase_44 AC 152 ms
201,696 KB
testcase_45 AC 152 ms
201,704 KB
testcase_46 AC 143 ms
201,652 KB
testcase_47 AC 142 ms
201,644 KB
testcase_48 AC 144 ms
201,632 KB
testcase_49 AC 144 ms
201,784 KB
testcase_50 AC 145 ms
201,700 KB
testcase_51 AC 145 ms
201,768 KB
testcase_52 AC 135 ms
201,684 KB
testcase_53 AC 141 ms
201,684 KB
testcase_54 AC 133 ms
201,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int dp[2][5050][5050];
int main()
{
	int n, k;
	cin>>n>>k;
	vector<P> v(n);
	for(int i=0; i<n; i++){
		cin>>v[i].first>>v[i].second;
	}
	sort(v.begin(), v.end(), greater<P>());
	for(int i=0; i<=n; i++) for(int j=0; j<=k; j++) dp[0][i][j]=dp[1][i][j]=-1;
	dp[0][0][0]=0;
	for(int i=0; i<n; i++){
		for(int j=0; j<=k; j++){
			dp[0][i+1][j]=max(dp[0][i+1][j], dp[0][i][j]);
			dp[1][i+1][j]=max(dp[1][i+1][j], dp[1][i][j]);
			if(dp[0][i][j]>=0 && j+v[i].first<=k){
				dp[1][i+1][j+v[i].first]=max(dp[1][i+1][j+v[i].first], dp[0][i][j]+v[i].second);
			}
			if(dp[1][i][j]>=0){
				dp[0][i+1][j]=max(dp[0][i+1][j], dp[1][i][j]+v[i].second);
			}
		}
	}
	int ans=0;
	for(int i=0; i<=k; i++) ans=max({ans, dp[0][n][i], dp[1][n][i]});
	cout<<ans<<endl;
	return 0;
}
0