結果
| 問題 |
No.1858 Gorgeous Knapsack
|
| ユーザー |
|
| 提出日時 | 2023-04-13 17:02:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 126 ms / 2,000 ms |
| コード長 | 908 bytes |
| コンパイル時間 | 1,042 ms |
| コンパイル使用メモリ | 82,576 KB |
| 実行使用メモリ | 199,264 KB |
| 最終ジャッジ日時 | 2024-10-09 14:20:05 |
| 合計ジャッジ時間 | 3,694 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 |
ソースコード
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<ctime>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long LL;
const int MR=5e3+10;
int n,m;
int v[MR],w[MR];
LL dp[MR][MR];
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) {
cin>>v[i]>>w[i];
for(int j=1;j<i;j++){
if(v[j]<v[i]){
swap(v[i],v[j]);
swap(w[i],w[j]);
}
}
}
// memset(dp,0x3f,sizeof dp);
// dp[0][0]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++){
dp[i][j]=dp[i-1][j];
if(j>=w[i]){
dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
}
}
}
LL ans=0;
for(int i=1;i<=n;i++){
ans=max(1ll*v[i]*dp[i][m],ans);
}
cout<<ans<<endl;
return 0;
}