| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 555607 | DeMen100ns | Knapsack (NOI18_knapsack) | C++17 | 129 ms | 5772 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.
/*
Author : DeMen100ns (a.k.a Vo Khac Trieu)
School : VNU-HCM High school for the Gifted
fuck you adhoc
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
const long long INF = 1e18 + 7;
const int MAXA = 1e9;
const int B = sqrt(N) + 5;
vector <int> obj[N];
int dp[N];
void solve()
{
int s, n;
cin >> s >> n;
for(int i = 1; i <= n; ++i){
int v, w, k;
cin >> v >> w >> k;
k = min(k, s / w);
int tmp = 1;
while (k){
int V = v * tmp, W = w * tmp;
obj[W].push_back(V);
k -= tmp;
tmp = min(tmp * 2, k);
}
}
int ma = 0;
for(int i = 1; i <= s; ++i){
sort(obj[i].begin(), obj[i].end(), greater<int>());
while (obj[i].size() > s / i){
obj[i].pop_back();
}
for(int v : obj[i]){
for(int w = s; w >= i; --w){
dp[w] = max(dp[w], dp[w - i] + v);
ma = max(ma, dp[w]);
}
}
}
cout << ma;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("codeforces.inp","r",stdin);
// freopen("codeforces.out","w",stdout);
int t = 1; // cin >> t;
while (t--)
{
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... | ||||
