제출 #1129243

#제출 시각아이디문제언어결과실행 시간메모리
1129243newbie__1Knapsack (NOI18_knapsack)C++20
49 / 100
245 ms327680 KiB
#include<bits/stdc++.h> #define ll long long #define F first #define S second #define pb push_back #define mpr make_pair const ll N=2e5 + 10 , mod=1e9 + 7; const double eps=1e-6; using namespace std; ll n,m,a,b,c,s,q,x,k; ll t[N]; string ch; vector<vector<ll>>v; ll res=0; int main(){ ios_base::sync_with_stdio (0); cin.tie(0),cout.tie(0); // freopen("time.in","r",stdin); // freopen("time.out","w",stdout); ll T=1; //cin>>T; while(T--){ cin>>s>>n; if(n>1){ vector<ll>v,w,c; for(ll i=0;i<n;i++){ ll x,y,z; cin>>x>>y>>z; for(ll j=0;j<z;j++){ v.pb(x); w.pb(y); } } n=v.size(); ll dp[n+5][s+5]; memset(dp,0,sizeof(dp)); for(ll i=1;i<=n;i++){ for(ll j=0;j<=s;j++){ dp[i][j]=dp[i-1][j]; if(j>=w[i-1]) dp[i][j]=max(dp[i][j],dp[i-1][j-w[i-1]]+v[i-1]); } } cout<<dp[n][s]<<"\n";; }else{ ll x,y,z; cin>>x>>y>>z; ll res=0,w=0; for(ll i=0;i<z;i++){ if(w+y<=s){ res+=x; w+=y; } } cout<<res<<"\n"; } } return 0; } /* 1 41 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...