제출 #825991

#제출 시각아이디문제언어결과실행 시간메모리
825991dijbkrKnapsack (NOI18_knapsack)C++14
0 / 100
3 ms3668 KiB
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; const ll maxn=200005; ll n,m; ll v[2001]; ll w[2001]; ll dp[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; ll sum=0; ll pos=1; for (ll i=1; i<=m; i++) { ll k; cin >> v[pos] >> w[pos] >> k; sum+=k; for (ll j=pos+1; j<pos+k; j++) { v[j]=v[pos]; w[j]=w[pos]; } pos=pos+k; } for (ll i=1; i<=maxn-1; i++) { dp[i]=1000000009; } for (ll i=1; i<=sum; i++) { for (ll j=maxn-1; j>=0; j--) { if (dp[j]+w[i]<=n) { dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]); } } } for (ll i=maxn-1; i>=0; i--) { if (dp[i]!=1000000009) { cout << i; break; } } }
#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...