Submission #1278941

#TimeUsernameProblemLanguageResultExecution timeMemory
1278941SSKMFKnapsack (NOI18_knapsack)C++20
100 / 100
106 ms6616 KiB
#include <bits/stdc++.h> using namespace std; vector <int> sir[2001]; int maxim[2001]; int main () { ios :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int limita , optiuni; cin >> limita >> optiuni; for (int indice = 1 ; indice <= limita ; indice++) { maxim[indice] = -1; } while (optiuni--) { int valoare , greutate , __limita; cin >> valoare >> greutate >> __limita; while (__limita && greutate <= limita) { int ramas = 1 + (__limita - 1) % 2; __limita -= ramas; while (ramas--) { sir[greutate].push_back(valoare); } __limita >>= 1; greutate <<= 1; valoare <<= 1; } } for (int greutate = 1 ; greutate <= limita ; greutate++) { if ((int)sir[greutate].size() > limita / greutate) { sort(sir[greutate].begin() , sir[greutate].end() , greater <int> ()); sir[greutate].resize(limita / greutate); } } for (int greutate = 1 ; greutate <= limita ; greutate++) { for (auto& valoare : sir[greutate]) { for (int indice = limita ; indice >= greutate ; indice--) { if (maxim[indice - greutate] != -1) { maxim[indice] = max(maxim[indice] , maxim[indice - greutate] + valoare); } } } } int rezultat = 0; for (int indice = 1 ; indice <= limita ; indice++) { rezultat = max(rezultat , maxim[indice]); } cout << rezultat; return 0; }
#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...