제출 #825976

#제출 시각아이디문제언어결과실행 시간메모리
825976dijbkrKnapsack (NOI18_knapsack)C++14
0 / 100
2 ms2004 KiB
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const int maxn=200005;

int n,m;
int v[2001];
int w[2001];
int dp[maxn];

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<=maxn-1; i++) {
      dp[i]=1e9;
   }
   for (int i=1; i<=sum; i++) {
      for (int 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 (int i=maxn-1; 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...