結果

問題 No.3014 岩井満足性問題
ユーザー mihhiael
提出日時 2025-01-25 13:19:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 469 ms / 3,000 ms
コード長 1,296 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 139,244 KB
実行使用メモリ 7,220 KB
最終ジャッジ日時 2025-01-25 22:42:59
合計ジャッジ時間 3,975 ms
ジャッジサーバーID
(参考情報)
judge9 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <vector>
#include <string>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;
using ll  = long long;
using pall = pair<ll,ll>;
using vell = vector<ll>;

template<class T, class U>
constexpr bool mini(T &var, const U &val) noexcept {
	const bool cmp = var > val;
	if(cmp) var = val;
	return cmp;
}
template<class T, class U>
constexpr bool maxi(T &var, const U &val) noexcept {
	const bool cmp = var < val;
	if(cmp) var = val;
	return cmp;
}

void solve();

int main(void) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}

void solve() {
	ll n, d, K;
	cin >> n >> d >> K;
	vell a(n), c(n);
	for(auto &e:a) cin >> e;
	for(auto &e:c) cin >> e;
	// dp[i][j] = i個, j美しさ.
	vector<vell> dp(d + 1, vell(K + 1, -1e18));
	dp[0][0] = 0;
	for(intmax_t i=0;i<intmax_t(n);i++) {
		auto nextdp = dp;
		for(intmax_t j=0;j < d;j++) {
			for(intmax_t k=0;k <= K;k++) {
				if(dp[j][k] == -1e18) continue;
				maxi(nextdp[j + 1][min(K, k + c[i])], dp[j][k] + a[i]);
			}
		}
		dp = std::move(nextdp);
	}
	if(dp[d][K] == -1e18) {
		cout << "No";
		return;
	}
	cout << dp[d][K];
}
0