結果
問題 | No.3014 岩井満足性問題 |
ユーザー |
![]() |
提出日時 | 2025-02-03 16:34:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 558 ms / 3,000 ms |
コード長 | 693 bytes |
コンパイル時間 | 3,895 ms |
コンパイル使用メモリ | 167,272 KB |
実行使用メモリ | 7,076 KB |
最終ジャッジ日時 | 2025-02-03 16:35:01 |
合計ジャッジ時間 | 7,043 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for( int i = 0; i < n; i++ ) using ll = long long; int main() { int N, D, K; cin >> N >> D >> K; vector<ll> a(N), c(N); rep(i, N) cin >> a[i]; rep(i, N) cin >> c[i]; ll INF = 1e18; vector<vector<ll>> dp(D + 1, vector<ll>(K + 1, -INF)); dp[0][0] = 0; auto chmax = [&](ll &d, ll s) { d = max(d, s); }; rep(i, N) { vector<vector<ll>> nxt = dp; rep(j, D) { rep(k, K + 1) { if(dp[j][k] == -INF) continue; ll t = k + c[i]; if(t > K) t = K; chmax(nxt[j + 1][t], dp[j][k] + a[i]); } } swap(dp, nxt); } ll ans = dp[D][K]; if(ans == -INF) cout << "No" << endl; else cout << ans << endl; }