結果
| 問題 |
No.2741 Balanced Choice
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-21 02:57:49 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 840 bytes |
| コンパイル時間 | 2,537 ms |
| コンパイル使用メモリ | 247,828 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 01:21:12 |
| 合計ジャッジ時間 | 3,412 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n,tw,d;
cin >> n >> tw >> d;
vector<long long> d0(tw+1,-4e18);
vector<long long> d1(tw+1,-4e18);
d0[0]=0;
d1[0]=0;
while(n>0){
n--;
long long t,w,v;
cin >> t >> w >> v;
if(t==0){
for(long long i=tw-w;i>=0;i--){
d0[i+w]=max(d0[i+w],d0[i]+v);
}
}
else{
for(long long i=tw-w;i>=0;i--){
d1[i+w]=max(d1[i+w],d1[i]+v);
}
}
}
long long res=0;
for(long long i=0;i<=tw;i++){
for(long long j=0;i+j<=tw;j++){
if(abs(i-j)<=d){
res=max(res,d0[i]+d1[j]);
}
}
}
// for(auto &nx : d0){cout << nx << " ";}cout << "\n";
// for(auto &nx : d1){cout << nx << " ";}cout << "\n";
cout << res << "\n";
return 0;
}