結果
| 問題 |
No.2741 Balanced Choice
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-21 00:40:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,837 bytes |
| コンパイル時間 | 1,180 ms |
| コンパイル使用メモリ | 103,236 KB |
| 実行使用メモリ | 199,296 KB |
| 最終ジャッジ日時 | 2024-10-12 23:00:46 |
| 合計ジャッジ時間 | 3,614 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 10 |
ソースコード
#include<iostream>
#include<iomanip>
#include<vector>
#include<math.h>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<cmath>
#include<ctime>
#include<bitset>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
using ll = long long;
using vec = vector<ll>;
using Graph = vector<vec>;
using Pair = pair<ll,ll>;
void debug1(vec v){
for(auto x:v)cout << x << ' ';
cout << endl;
}
void debug2(vector<Pair> v){
for(auto x:v)cout << '(' << x.first << ',' << x.second << ')' << endl;
}
void debug3(Graph v){
rep(i,0,v.size()-1)debug1(v[i]);
cout << endl;
}
int main(){
int n,w,d;
cin >> n >> w >> d;
Graph zer = {{0,0}},one = {{0,0}};
rep(i,1,n){
int t,wi,v;
cin >> t >> wi >> v;
if(t == 0)zer.push_back({wi,v});
else one.push_back({wi,v});
}
ll n1 = zer.size(),n2 = one.size();
Graph dp1(n1,vec(w+1,-1)),dp2(n2,vec(w+1,-1));
dp1[0][0] = 0;dp2[0][0] = 0;
if(n1 > 1)rep(i,1,n1-1){
dp1[i][0] = 0;
rep(ww,0,w){
if(dp1[i-1][ww] == -1)continue;
if(ww + zer[i-1][0] > w)continue;
dp1[i][ww + zer[i][0]] = max(dp1[i][ww + zer[i][0]],dp1[i-1][ww] + zer[i][1]);
}
}
if(n2 > 1)rep(i,1,n2-1){
dp2[i][0] = 0;
rep(ww,0,w){
if(dp2[i-1][ww] == -1)continue;
if(ww + one[i-1][0] > w)continue;
dp2[i][ww + one[i][0]] = max(dp2[i][ww + one[i][0]],dp2[i-1][ww] + one[i][1]);
}
}
ll ans = 0;
rep(i,0,w){
if(dp1[n1-1][i] == -1)continue;
rep(j,max(0,i-d),min(w-i,i+d)){
if(dp2[n2-1][j] == -1)continue;
ans = max(ans,dp1[n1-1][i] + dp2[n2-1][j]);
}
}
//debug3(dp1);
//debug3(dp2);
cout << ans;
}