제출 #1185944

#제출 시각아이디문제언어결과실행 시간메모리
1185944trunz111Knapsack (NOI18_knapsack)C++20
73 / 100
1097 ms16796 KiB
#include <bits/stdc++.h>

using namespace std;
#define int long long
int s, n;
vector<pair<int,int>> a;

void Solve()
{
    vector<int> dp(s+5, 0);
    for (int i = 0; i < a.size(); i++)
    {
        for (int m = s; m >= a[i].first; m--)
        {
            dp[m] = max(dp[m], dp[m-a[i].first] + a[i].second);
            //cout << dp[i] << " ";
        }
        //cout << "\n";
    }
    cout << dp[s];
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> s >> n;
    for (int i = 1; i <= n; i++)
    {
        int v, w, k; cin >> v >> w >> k;

        int cnt = 1;
        while (k >= cnt)
        {
            a.push_back({cnt*w, cnt*v});
            k -= cnt;
            cnt *= 2;
        }

        if (k > 0) a.push_back({k*w, k*v});
    }
    //for (pair<int,int> cur : a) cout << cur.first << ", " << cur.second << "\n";
    Solve();
    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...