結果

問題 No.2741 Balanced Choice
ユーザー cho435cho435
提出日時 2024-04-20 01:53:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 854 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 203,288 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 01:53:38
合計ジャッジ時間 4,474 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
5,248 KB
testcase_01 AC 143 ms
5,376 KB
testcase_02 AC 139 ms
5,376 KB
testcase_03 AC 150 ms
5,376 KB
testcase_04 AC 144 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 76 ms
5,376 KB
testcase_08 AC 107 ms
5,376 KB
testcase_09 AC 72 ms
5,376 KB
testcase_10 AC 104 ms
5,376 KB
testcase_11 AC 110 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

void chmax(ll &a,ll b){
	if(a<b) a=b;
}

int main(){
	int N,W,D;
	cin>>N>>W>>D;
	vector<vector<int>> wt(2),vt(2);
	rep(i,N){
		int t,w,v;
		cin>>t>>w>>v;
		wt.at(t).push_back(w);
		vt.at(t).push_back(v);
	}
	vector<vector<ll>> ans(2);
	rep(t,2){
		vector<int> &w=wt.at(t);
		vector<int> &v=vt.at(t);
		int m=w.size();
		vector<ll> dp(W+1,-1e18);
		dp.at(0)=0;
		rep(i,m){
			vector<ll> ndp(W+1,-1e18);
			rep(j,W+1){
				if(dp.at(j)<0) continue;
				chmax(ndp.at(j),dp.at(j));
				if(j+w.at(i)<=W){
					chmax(ndp.at(j+w.at(i)),dp.at(j)+v.at(i));
				}
			}
			swap(dp,ndp);
		}
		swap(ans.at(t),dp);
	}
	ll res=0;
	rep(i,W+1) rep(j,W+1){
		if(abs(i-j)<=D&&i+j<=W){
			chmax(res,ans.at(0).at(i)+ans.at(1).at(j));
		}
	}
	cout<<res<<'\n';
}
0