제출 #1188618

#제출 시각아이디문제언어결과실행 시간메모리
1188618abcd1234Knapsack (NOI18_knapsack)C++20
73 / 100
1093 ms484 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using ll = long long;

int main()
{
    int s, n; cin >> s >> n;
    vector<priority_queue<ll, vector<ll>, greater<ll>>> store(s + 1);
    ll v; int w, k;
    for(int i = 0; i < n; i++)
    {
        cin >> v >> w >> k;
        int j = min(k, s / w);
        while(j > 0)
        {
            store[w].push(v);
            if(store[w].size() > s / w) store[w].pop();
            j--;
        }
    }
    vector<int> dp(s + 1, 0);
    for(int i = 1; i <= s; i++)
    {
        while(!store[i].empty())
        {
            ll u = store[i].top(); store[i].pop();
            for(int j = s; j >= i; j--) dp[j] = max(dp[j - i] * 1LL + u, dp[j] * 1LL);
        }
    }
    cout << dp[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...