結果
| 問題 |
No.1858 Gorgeous Knapsack
|
| ユーザー |
|
| 提出日時 | 2022-03-10 23:07:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 581 bytes |
| コンパイル時間 | 1,673 ms |
| コンパイル使用メモリ | 173,972 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 23:16:49 |
| 合計ジャッジ時間 | 3,329 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
vector<array<int,2>>A(N);
for(int i=0;i<N;i++)cin>>A[i][0]>>A[i][1];
sort(A.begin(),A.end(),[](array<int,2>a, array<int,2>b){
return a[0]>b[0];
});
long long ans=0;
vector<long long>dp(M+1,-1e18);
dp[0]=0;
for(int i=0;i<N;i++){
for(int j=M;j>=0;j--){
if(j+A[i][1]<=M&&dp[j]>=0){
dp[j+A[i][1]]=max(dp[j+A[i][1]],dp[j]+A[i][0]);
ans=max(ans,dp[j+A[i][1]]*A[i][0]);
}
}
}
cout<<ans<<'\n';
}