| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1332845 | yumemystery | Knapsack (NOI18_knapsack) | C++20 | 45 ms | 1748 KiB |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int W,n;
cin >> W >> n;
vector<ll>dp(W+1,0);
map<int,vector<pair<int,int>>>mp;
for (int i=1; i<=n; i++) {
int v,w,k;
cin >> v >> w >> k;
mp[w].push_back({v,k});
}
for (auto &a : mp) {
int w = a.first;
if (w > W) break;
sort(a.second.begin(),a.second.end());
reverse(a.second.begin(),a.second.end());
int sum = 0;
for (auto &item : a.second) {
int k = item.second;
while (k > 0) {
sum += w;
if (sum > W) break;
for (int i=W; i>=w; i--) {
dp[i] = max(dp[i],dp[i-w]+item.first);
}
--k;
}
if (sum > W) break;
}
}
ll ans = 0;
for (int i=1; i<=W; i++) ans = max(ans,dp[i]);
cout << ans;
}| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
