結果
| 問題 |
No.2232 Miser's Gift
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2023-03-05 14:58:43 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 2,000 ms |
| コード長 | 998 bytes |
| コンパイル時間 | 3,388 ms |
| コンパイル使用メモリ | 142,740 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-18 01:34:43 |
| 合計ジャッジ時間 | 9,571 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 55 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N, weight;
cin >> N >> weight;
vector<ll> W(N);
vector<ll> V(N);
for (int i = 0; i < N; ++i) {
cin >> W[i] >> V[i];
}
vector<ll> dp(weight + 1, -1);
dp[0] = 0;
ll max_v = 0;
for (int i = 0; i < N; ++i) {
ll w = W[i];
ll v = V[i];
for (int j = weight - w; j >= 0; --j) {
if (dp[j] == -1) continue;
int nw = j + w;
dp[nw] = max(dp[nw], dp[j] + v);
max_v = max(max_v, dp[nw]);
}
}
ll min_v = LLONG_MAX;
vector<ll> ans;
for (int w = 0; w < weight; ++w) {
ll v = max(1LL, max_v - max(0LL, dp[w]) + 1);
min_v = min(min_v, v);
ans.push_back(min_v);
}
reverse(ans.begin(), ans.end());
for (ll v : ans) {
cout << v << endl;
}
return 0;
}
siman