# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
447010 | cpp219 | Knapsack (NOI18_knapsack) | C++14 | 74 ms | 3692 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.
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 2e3 + 9;
const ll Log2 = 21;
const ll inf = 1e9 + 7;
vector<LL> v[N];
ll s,n,a,b,c,dp[N];
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>s>>n;
for (ll i = 1;i <= n;i++){
cin>>a>>b>>c;
v[b].push_back({a,c});
}
for (ll i = 1;i <= s;i++){
sort(v[i].begin(),v[i].end(),greater<LL> ());
ll total = i;
for (auto now : v[i]){
if (total > s) break;
for (ll j = 1;j <= now.sc&&total <= s;j++,total += i)
for (ll k = s;k >= i;k--)
dp[k] = max(dp[k],dp[k - i] + now.fs);
}
}
cout<<dp[s];
}
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... |