# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
776305 | coolavy999 | Knapsack (NOI18_knapsack) | C++17 | 95 ms | 3608 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int S, N, V, W, K;
vector<pair<int, int>> A[2001];
long long dp[2001], answer;
int main() {
cin >> S >> N;
for (int i = 0; i < N; i++) {
cin >> V >> W >> K;
A[W].push_back(make_pair(V, K));
}
for (int i = 1; i <= S; i++) {
sort(A[i].begin(), A[i].end(), greater<pair<int, int>>());
int index = 0;
for (int j = 0; j < S / i; j++) {
if (index >= A[i].size())
break;
for (int k = S; k >= i; k--) {
dp[k] = max(dp[k], dp[k - i] + A[i][index].first);
answer = max(answer, dp[k]);
}
A[i][index].second--;
if (A[i][index].second == 0)
index++;
}
}
cout << answer << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |