Submission #881779

#TimeUsernameProblemLanguageResultExecution timeMemory
881779MicrofsKnapsack (NOI18_knapsack)C++14
73 / 100
352 ms262144 KiB
#include <iostream> #include <vector> #include <cstring> #include <algorithm> #include <climits> #include <queue> using namespace std; const int MAXN = 2003; long long dp[MAXN]; vector<priority_queue<int>> 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(v); } long long maxmax = -1; for(int i = 1; i <= s; i++){ // item ind int smol = s/i; while(items[i].size() && smol){ //num of items taken auto l = items[i].top(); items[i].pop(); smol--; for(int k = s; k >= i; k--){ dp[k] = max(dp[k], dp[k-i]+l); } } } 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...