Submission #881777

#TimeUsernameProblemLanguageResultExecution timeMemory
881777MicrofsKnapsack (NOI18_knapsack)C++14
73 / 100
148 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(MAXN); 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; int smol = min(s/w, k); for(int j = 0; j < smol; j++)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 = items[i].size(); smol = min(smol,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 <= s; 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...