# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107582 | adkjt | Knapsack (NOI18_knapsack) | C++14 | 1077 ms | 532 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>
using namespace std;
#define f first
#define s second
vector<pair<int,int>> V[2222];
int dp[2222];
pair<int,pair<int,int>> a[111111];//v,w,k
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int s,n;
cin>>s>>n;
for(int i=1; i<=n; i++)
{
cin>>a[i].f>>a[i].s.f>>a[i].s.s;
if(a[i].s.f>s) continue;
V[a[i].s.f].push_back({-a[i].f,a[i].s.s});
}
for(int i=1; i<=s; i++) dp[i]=-1;
for(int i=1; i<=s; i++)
sort(V[i].begin(),V[i].end());
for(int i=1; i<=s; i++)
{
if (V[i].empty()) continue;
int j = 0;
for(auto x:V[i])//v,k
{
re:
for (int w = s; w - i >= 0; w--)
{
dp[w] = max(dp[w], dp[w - i] - x.f);
}
x.s--;
if (j >= V[i].size()) {
break;
}
if (x.s == 0)
{
j++;
continue;
}
else goto re;
}
}
int ans=0;
for(int i=1; i<=s; i++)
ans=max(ans,dp[i]);
cout<<ans;
}
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... |