結果

問題 No.3329 Only the Rightest Choice is Right!!!
コンテスト
ユーザー ルビサファせだい
提出日時 2025-11-04 00:48:22
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,656 bytes
コンパイル時間 3,349 ms
コンパイル使用メモリ 288,260 KB
実行使用メモリ 144,256 KB
最終ジャッジ日時 2025-11-04 00:48:39
合計ジャッジ時間 15,966 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 2
other AC * 53 RE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/fenwicktree.hpp>
#include <atcoder/segtree.hpp>
#include <atcoder/modint.hpp>
#include <atcoder/dsu.hpp>
#include <atcoder/lazysegtree.hpp>

using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<>>;
ll ll_min = numeric_limits<ll>::min();
ll ll_max = numeric_limits<ll>::max();
ll ALPHABET_N = 26;
using mint = modint998244353;
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++)
#define all(a) a.begin(), a.end()

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n, mx_w;
	cin >> n >> mx_w;
	vector<ll> V(n), W(n);
	rep(i, n) cin >> V[i];
	rep(i, n) cin >> W[i];
	// i番目まで見て,重さw以下の最大価値
	vector dp(n, vector(mx_w + 1, make_pair(0, -1LL)));
	for (ll cw = W.back(); cw <= mx_w; cw++)
	{
		dp.back()[cw] = {V.back(), n - 1};
	}
	for (ll i = n - 2; i >= 0; i--)
	{
		ll v = V[i];
		ll w = W[i];
		for (ll cw = 0; cw <= mx_w; cw++)
		{
			dp[i][cw] = dp[i + 1][cw];
			ll pw = cw - w;
			if (pw < 0)
				continue;
			auto &[mx_v, by] = dp[i][cw];
			if (mx_v < dp[i + 1][pw].first + v)
			{
				mx_v = dp[i + 1][pw].first + v;
				by = i;
			}
		}
	}
	vector<ll> ans;
	ll p = 0;
	ll cw = mx_w;
	while (true)
	{
		auto [mx_v, by] = dp[p][cw];
		if (by == -1)
			break;
		ans.push_back(by + 1);
		cw = cw - W[by];
		p = by + 1;
	}
	cout << ans.size() << endl;
	rep(i, ans.size()) cout << ans[i] << " \n"[i == ans.size() - 1];
	return 0;
}
0