結果
| 問題 |
No.2741 Balanced Choice
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-20 01:53:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 168 ms / 2,000 ms |
| コード長 | 854 bytes |
| コンパイル時間 | 2,420 ms |
| コンパイル使用メモリ | 202,868 KB |
| 最終ジャッジ日時 | 2025-02-21 06:00:03 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 |
ソースコード
#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';
}