結果
問題 | No.1858 Gorgeous Knapsack |
ユーザー |
![]() |
提出日時 | 2023-03-28 02:25:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,022 bytes |
コンパイル時間 | 3,893 ms |
コンパイル使用メモリ | 254,412 KB |
最終ジャッジ日時 | 2025-02-11 18:46:57 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 37 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;using ll=long long;using ld=long double;ld pie=3.141592653589793;ll inf=1444999994;ll mod=1000000007;int main(){ll n,m;cin >> n >> m;vector<pair<ll,ll>>p(n);for (ll i = 0; i < n; i++){cin >> p[i].first >> p[i].second;}sort(p.begin(),p.end());reverse(p.begin(),p.end());vector<ll>v(n),w(n);for (ll i = 0; i < n; i++){v[i]=p[i].first;w[i]=p[i].second;}vector<ll>dp(m+1,-1);dp[0]=0;ll ans=0;for (ll i = 0; i < n; i++){for (ll j = m; j >=0; j--){if (dp[j]==-1){continue;}if (j+w[i]<=m){if (dp[j+w[i]]<dp[j]+v[i]){dp[j+w[i]]=dp[j]+v[i];ans=max(ans,dp[j+w[i]]*v[i]);}}}}cout << ans << endl;}