Submission #881776

#TimeUsernameProblemLanguageResultExecution timeMemory
881776MicrofsKnapsack (NOI18_knapsack)C++14
73 / 100
223 ms262144 KiB
#include <iostream> #include <vector> #include <cstring> #include <algorithm> #include <climits> using namespace std; const int MAXN = 2003; long long dp[MAXN]; vector<vector<long long>> items(2010); int main(){ for(int i =0; i < MAXN; i++)dp[i]=0; int s,n; cin >> s >> n; for(int i = 0; i < n; i++){ int v,w,k; cin >> v >> w >> k; for(int j = 0; j < s/w; j++){ if(j >= k)break; items[w].push_back(v); } } long long maxmax = -1; for(int i =0; i <= s; i++)sort(items[i].begin(),items[i].end(),greater<int>()); for(int i = 1; i <= s; i++){ // item ind int smol = min((int)items[i].size(),s/i); for(int j = 0; j < smol; j++){ //num of items taken for(int k = s; k >= i; k--){ dp[k] = max(dp[k], dp[k-i]+items[i][j]); } } } for(int i =0; i < MAXN; i++)maxmax = max(maxmax,dp[i]); cout << maxmax << 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...