# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883822 | PieArmy | Knapsack (NOI18_knapsack) | C++14 | 1 ms | 616 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>
typedef long long ll;
#define yem(re) (1ll<<(ll(re)))
#define endl '\n'
#define pb push_back
#define int long long
#define mid ((left+right)/2)
#define L(emanuelLasker,joseRaulCapablanca,anatolyKarpov) for(int emanuelLasker=(joseRaulCapablanca);emanuelLasker<=(anatolyKarpov);emanuelLasker++)
#define R(magnusCarlsen,paulMorphy,bobbyFischer) for(int magnusCarlsen=(paulMorphy);magnusCarlsen>=(bobbyFischer);magnusCarlsen--)
#define cint(vladimirKramnik) int vladimirKramnik;cin>>vladimirKramnik
#define inf (2e18+5)
#define sc second
#define fr first
#define Bismillahirrahmanirrahim ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cinarr(mikhailTal) for(auto &garryKasparov:mikhailTal)cin>>garryKasparov;
#define all(mustafaKemalAtaturk) mustafaKemalAtaturk.begin(),mustafaKemalAtaturk.end()
using namespace std;
mt19937 rng(chrono::high_resolution_clock().now().time_since_epoch().count());
void code(){
int n,k;cin>>k>>n;
vector<pair<int,pair<int,int>>>v;
L(i,0,n-1){
cint(val);cint(cos);cint(num);
v.pb({val,{cos,num}});
}
sort(all(v));
vector<int>dp(k+1,-1);
dp[0]=0;
R(i,n-1,0){
vector<int>dp2(k+1,-1);
int val=v[i].fr,cos=v[i].sc.fr,num=v[i].sc.sc;
L(j,0,k)dp2[i]=dp[i];
L(j,0,k){
if(dp[j]==-1)continue;
int x=min(ll((k-j)/cos),num);
dp2[j+(x*cos)]=max(dp2[j+(x*cos)],dp[j]+(x*val));
}
swap(dp2,dp);
}
int ans=0;
for(int x:dp)ans=max(x,ans);
cout<<ans;
}
int32_t main(){
Bismillahirrahmanirrahim
int t=1;
bool usaco=0;
if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
if(!t)cin>>t;
while(t--){code();cout<<endl;}
return 0;
}
//Haven't checked tutorial yet...
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... |