제출 #633605

#제출 시각아이디문제언어결과실행 시간메모리
633605ojoConmigoKnapsack (NOI18_knapsack)C++17
100 / 100
72 ms36300 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll s,n; cin >> s >> n; vector<vector<pair<ll,ll>>> v(s+1); for(int i=0; i<n; i++){ ll val,w,k; cin >> val >> w >> k; v[w].push_back({val,k}); } for(int i=1; i<=s; i++){ sort(begin(v[i]),end(v[i]),greater<pair<ll,ll>>()); } vector<vector<ll>> dp(s+1,vector<ll> (s+1,0)); for(int i=1; i<=s; i++){ for(int j=1; j<=s; j++){ dp[i][j] = max(dp[i][j],dp[i-1][j]); ll t = 1, cont = 0; for(int x=0; x<(int)v[i].size(); x++){ ll f = 1; while(f <= v[i][x].second){ if(j - t*i < 0) goto fin; dp[i][j] = max(dp[i][j],dp[i-1][j - t*i] + f*v[i][x].first + cont); t++; f++; } cont += (v[i][x].first*v[i][x].second); } fin: continue; } } cout << dp[s][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...