제출 #1261634

#제출 시각아이디문제언어결과실행 시간메모리
1261634kaloyanKnapsack (NOI18_knapsack)C++20
37 / 100
1 ms328 KiB
#include <bits/stdc++.h>

using namespace std;

int S, N;
vector<pair<int, int>> items;

void solve()
{
    cin >> S >> N;

    int price, award, cnt;

    vector<int> dp(S + 1, 0);

    for(int i = 0 ; i < N ; ++i)
    {
        cin >> award >> price >> cnt;

        int p = 1;

        while(p <= cnt)
        {
            cnt -= p;

            for(int j = S ; j >= price * p ; --j)
            {
                dp[j] = max(dp[j], dp[j - price * p] + award * p);
            }

            p *= 2;
        }

        if(cnt)
        {
            for(int j = S ; j >= price * cnt ; --j)
            {
                dp[j] = max(dp[j], dp[j - price * cnt] + award * cnt);
            }
        }

        
    }


    cout << dp[S] << "\n";
}

void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();
    solve();
}
#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...