結果
| 問題 |
No.1858 Gorgeous Knapsack
|
| ユーザー |
Nachia
|
| 提出日時 | 2022-02-26 20:10:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 2,000 ms |
| コード長 | 835 bytes |
| コンパイル時間 | 2,235 ms |
| コンパイル使用メモリ | 85,544 KB |
| 最終ジャッジ日時 | 2025-01-28 03:32:38 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i64 = long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using modint = atcoder::static_modint<998244353>;
int N,M;
vector<pair<int,int>> VW;
vector<i64> dp;
int main(){
cin >> N >> M;
dp.assign(M+1, 0);
VW.resize(N);
rep(i,N){ int u,v; cin >> u >> v; VW[i] = {u,v}; }
sort(VW.rbegin(), VW.rend());
i64 ans = 0;
for(auto [v,w] : VW){
for(int to=M; to>=w; to--){
dp[to] = max(dp[to], dp[to-w] + v);
}
for(auto a : dp) ans = max(ans, a * v);
}
cout << ans << endl;
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia