結果
| 問題 |
No.1858 Gorgeous Knapsack
|
| ユーザー |
|
| 提出日時 | 2023-09-02 18:55:07 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 977 bytes |
| コンパイル時間 | 3,971 ms |
| コンパイル使用メモリ | 254,548 KB |
| 実行使用メモリ | 199,168 KB |
| 最終ジャッジ日時 | 2024-06-12 01:21:53 |
| 合計ジャッジ時間 | 6,053 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 27 WA * 10 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
long findMaxEfficiency(int m, vector<int> values, vector<int> resources) {
int n = values.size();
vector<int> order(n);
iota(order.begin(),order.end(),0);
sort(order.begin(),order.end(), [&](const int& l, const int& r){
return values[l] > values[r];
});
vector<vector<int>> dp0(n, vector<int> (m+1,0)), dp1(n, vector<int> (m+1,0));
dp1[0][resources[order[0]]] = values[order[0]];
for(int i=1; i<n; i++){
for(int j=1; j<=m; j++){
dp0[i][j] = max(dp0[i-1][j], dp1[i-1][j]);
if(resources[order[i]] <= j) dp1[i][j] = values[order[i]] + max(dp0[i-1][j-resources[order[i]]], dp1[i-1][j-resources[order[i]]]);
}
}
long ans = 0;
for(int i=0; i<n; i++) ans = max(ans, 1L*values[order[i]]*dp1[i][m]);
return ans;
}
int main(){
int n,m; cin>>n>>m;
vector<int> values(n), resources(n);
for(int i=0; i<n; i++) cin>>values[i]>>resources[i];
cout<<findMaxEfficiency(m,values,resources)<<"\n";
}