제출 #825973

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