結果
| 問題 |
No.1858 Gorgeous Knapsack
|
| ユーザー |
|
| 提出日時 | 2022-03-07 18:47:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 1,080 bytes |
| コンパイル時間 | 1,672 ms |
| コンパイル使用メモリ | 174,136 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-22 13:52:10 |
| 合計ジャッジ時間 | 3,236 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
template <typename T, typename U>
auto Sum(T a, U b) -> decltype(a + b)
{
return a + b;
}
template <typename T, typename U>
inline bool amax(T &a, U b)
{
if (b > a)
{
a = b;
return true;
}
return false;
}
template <typename T, typename U>
inline bool amin(T &a, U b)
{
if (b < a)
{
a = b;
return true;
}
return false;
}
int main()
{
int N, M;
cin >> N >> M;
vector<P> items(N);
rep(i, N) cin >> items[i].first >> items[i].second;
sort(items.begin(), items.end(), [](P x, P y)
{ return x.first > y.first; });
ll ans = 0;
vector<ll> dp(M + 1);
for (auto &p : items)
{
int v = p.first, w = p.second;
for (int j = M; j >= w; --j)
{
amax(dp[j], dp[j - w] + v);
}
amax(ans, dp[M] * v);
}
cout << ans << endl;
}