結果
問題 | No.2741 Balanced Choice |
ユーザー |
|
提出日時 | 2024-04-20 14:21:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 1,168 bytes |
コンパイル時間 | 1,970 ms |
コンパイル使用メモリ | 196,696 KB |
最終ジャッジ日時 | 2025-02-21 06:35:05 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 |
ソースコード
#include <bits/stdc++.h>using namespace std;//#include<atcoder/all>//using namespace atcoder;using ll = long long int;using ull = unsigned long long int;using ld = long double;constexpr ll MAX = 2000000000000000000;constexpr ld PI = 3.14159265358979;constexpr ll MOD = 0;//2024948111;ld dotorad(ld K){ return PI * K / 180.0; }ld radtodo(ld K){ return K * 180.0 / PI; }mt19937 mt;void randinit(){ srand((unsigned)time(NULL));mt = mt19937(rand()); }int main(){ll N,W,D;cin >> N >> W >> D;vector<ll> DP1(W + 1,-MAX),DP2(W + 1,-MAX);DP1[0] = 0;DP2[0] = 0;for(ll i = 0;i < N;i++){ll t,w,v;cin >> t >> w >> v;if(t == 1){for(ll j = W;j >= w;j--){DP1[j] = max(DP1[j],DP1[j - w] + v);}}else{for(ll j = W;j >= w;j--){DP2[j] = max(DP2[j],DP2[j - w] + v);}}}ll ans = 0;for(ll i = 0;i <= W;i++){for(ll j = 0;j <= W;j++){if(i + j <= W && abs(i - j) <= D){ans = max(ans,DP1[i] + DP2[j]);}}}cout << ans << endl;}