| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1039232 | vjudge1 | Knapsack (NOI18_knapsack) | C++14 | 38 ms | 3788 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<bits/stdc++.h>
#define file "D"
#define ll long long
using namespace std;
const int maxN = 2e3 + 5;
struct points{
int v, k;
};
bool cmp(points a, points b){
if (a.v != b.v)
return a.v > b.v;
return a.k > b.k;
}
int t, n;
int s;
ll dp[maxN];
vector< points > a[maxN];
void solve(){
for (int i = 1; i <= s; ++i){
if (!a[i].size())
continue;
sort(a[i].begin(), a[i].end(), cmp);
int index = 0;
for (int j = 1; j * i <= s; ++j){
if (index == a[i].size())
break;
for (int q = s; q >= i; --q)
dp[q] = max(dp[q], dp[q - i] + a[i][index].v);
a[i][index].k-= 1;
if (a[i][index].k == 0)
++index;
}
}
cout << dp[s];
}
signed main(){
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
cin.tie(NULL)->sync_with_stdio(0);
t = 1;
while (t--){
cin >> s >> n;
for (int i = 1; i <= n; ++i){
int v, w, k;
cin >> v >> w >> k;
a[w].push_back({v, k});
}
solve();
}
}
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... | ||||
