제출 #1129212

#제출 시각아이디문제언어결과실행 시간메모리
1129212jackofall718Knapsack (NOI18_knapsack)C++20
12 / 100
1 ms328 KiB
#include <bits/stdc++.h>
//NOI 2018 PRELIMS
#define ll long long int
#define endl '\n'
#define vn vector <ll>
using namespace std;
const int MAX_N = 1e9 + 7;
#define pii pair <ll,ll>
const ll INF = 0x3f3f3f3f3f3f3f3f;

#define pb push_back  

#define srt(vp) sort(vp.begin(), vp.end()) 

int main() {
  ios::sync_with_stdio(false);        
  cin.tie(nullptr);
  ll s,n;
  cin>>s>>n;
  vn weights;
  vn prices;
  map <ll,ll> freq;
  for (int i=0;i<n;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    ll max1=min(c,(s/b)+1);
    if (freq[b]){
        max1=min(max1,(s/b)-1-freq[b]);
    }
    for (int j=0;j<max1;j++){
        prices.pb(a);
        weights.pb(b);
    }
    freq[b] += max1;
  }
    vn dp (s+1,0);
    
for (int i = 0; i < weights.size(); i++) {
    for (int j = s; j >= weights[i]; j--) {
        dp[j] = max(dp[j], dp[j - weights[i]] + prices[i]);
    }
}

    cout<<dp[s]<<endl;


  
 
   
}
#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...