| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 920533 | AndrijaM | Knapsack (NOI18_knapsack) | C++14 | 1 ms | 348 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;
long long s,n;
vector<pair<long long,pair<long long,long long>>>x;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin>>s>>n;
long long dp[s+1];
long long D[s+1];
memset(dp,0,sizeof dp);
for(long long i=0;i<n;i++)
{
long long v,w,k;
cin>>v>>w>>k;
x.push_back({v,{w,k}});
}
long long ans=0;
for(long long i=0;i<n;i++)
{
for(int idx=0;idx<s+1;idx++)
{
D[idx]=dp[idx];
}
for(long long j=min(s,x[i].second.second);j>=1;j--)
{
if(s-j*x[i].second.first<=0)break;
for(long long p=s;p>=j*x[i].second.first;p--)
{
dp[p]=max(max(D[p],dp[p]),D[p-j*x[i].second.first]+j*x[i].first);
}
///cout<<i<<" "<<j<<" "<<dp[20]<<endl;
}
}
cout<<dp[s]<<endl;
}
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... | ||||
