結果

問題 No.2741 Balanced Choice
ユーザー rii922rii922
提出日時 2024-04-20 18:49:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 2,068 bytes
コンパイル時間 3,620 ms
コンパイル使用メモリ 284,408 KB
実行使用メモリ 199,168 KB
最終ジャッジ日時 2024-04-20 18:49:47
合計ジャッジ時間 6,242 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 202 ms
198,912 KB
testcase_01 AC 219 ms
199,168 KB
testcase_02 AC 224 ms
199,040 KB
testcase_03 AC 228 ms
198,784 KB
testcase_04 AC 253 ms
198,912 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 123 ms
129,536 KB
testcase_08 AC 172 ms
176,512 KB
testcase_09 AC 118 ms
123,136 KB
testcase_10 AC 136 ms
140,928 KB
testcase_11 AC 174 ms
177,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmaxeq(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmineq(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
bool yes(bool a) { cout << (a?"yes":"no") << endl; return a; }
bool Yes(bool a) { cout << (a?"Yes":"No") << endl; return a; }
bool YES(bool a) { cout << (a?"YES":"NO") << endl; return a; }
void _main();
int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); _main(); return 0; }

ll INF = 1001001001;

void _main() {
	ll N, W, D; cin >> N >> W >> D;
	vl w0, v0, w1, v1;
	rep(i, N) {
		ll t, w, v; cin >> t >> w >> v;
		if (t == 0) {
			w0.push_back(w);
			v0.push_back(v);
		}
		else {
			w1.push_back(w);
			v1.push_back(v);
		}
	}
	ll N0 = w0.size();
	ll N1 = w1.size();
	vvl dp0(N0+1, vl(W+1, -INF)), dp1(N1+1, vl(W+1, -INF));
	dp0[0][0] = dp1[0][0] = 0;
	rep(i, N0) rep(j, W+1) {
		dp0[i+1][j] = dp0[i][j];
		if (j-w0[i] >= 0) chmax(dp0[i+1][j], dp0[i][j-w0[i]]+v0[i]);
	}
	rep(i, N1) rep(j, W+1) {
		dp1[i+1][j] = dp1[i][j];
		if (j-w1[i] >= 0) chmax(dp1[i+1][j], dp1[i][j-w1[i]]+v1[i]);
	}
	ll ans = 0;
	rep(i, W+1) rep(j, W+1) {
		if (abs(i-j) > D || i+j > W) continue;
		chmax(ans, dp0[N0][i]+dp1[N1][j]);
	}
	cout << ans << endl;
}
0