結果
問題 |
No.1858 Gorgeous Knapsack
|
ユーザー |
|
提出日時 | 2022-03-10 23:26:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 63 ms / 2,000 ms |
コード長 | 906 bytes |
コンパイル時間 | 2,227 ms |
コンパイル使用メモリ | 199,164 KB |
最終ジャッジ日時 | 2025-01-28 08:01:19 |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 37 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define ar array #define sz(x) ((int)x.size()) template <class T,class S> inline bool chmin(T &a,const S &b) {return (a> b? a= b, 1: 0);} template <class T,class S> inline bool chmax(T &a,const S &b) {return (a< b? a= b, 1: 0);} int main(){ ios_base::sync_with_stdio(false),cin.tie(0); int n, m; cin >> n >> m; vector <ar<ll, 2>> arr(n); for(int i = 0, v, w;i < n;i++){ cin >> v >> w; arr[i][0] = v; arr[i][1] = w; } sort(all(arr), greater<ar<ll, 2>>()); ll dp[m + 5] = {}, ans = 0; for(int i = 0;i < n;i++){ for(int j = m;j >= arr[i][1];j--){ chmax(dp[j], dp[j - arr[i][1]] + arr[i][0]); chmax(ans, (dp[j - arr[i][1]] + arr[i][0]) * arr[i][0]); } } cout << ans << "\n"; return 0; }