Submission #1003675

#TimeUsernameProblemLanguageResultExecution timeMemory
1003675ypratikKnapsack (NOI18_knapsack)C++17
37 / 100
138 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nline "\n"
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;

const int N = 0;

void Solve()
{
    int s, n;
    cin >> s >> n;
    vector<pair<int, int>> a;
    a.push_back({0, 0});
    for (int i = 0; i < n; ++i)
    {
        int x, y, z;
        cin >> x >> y >> z;
        while (z--)
        {
            a.push_back({x, y});
        }
    }
    n=a.size();
    vector<vector<int>> dp(n + 1, vector<int>(s + 1, -INF));
    // vector<int> dp(s + 1, -INF);
    dp[0][0] = 0;

    for (int i = 1; i <= a.size(); ++i)
    {
        for (int j = 0; j < s + 1; ++j)
        {
            dp[i][j]=dp[i-1][j];
            if (j - a[i].second >= 0)
            {
                dp[i][j] = max(dp[i][j], dp[i-1][j - a[i].second] + a[i].first);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < s+1; ++i)
    {
        ans = max(ans, dp[n][i]);
    }

    cout << ans << nline;

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#ifdef SIEVE
    sieve();
#endif
#ifdef NCR
    init();
#endif
    int t = 1;
    while (t--) Solve();
    return 0;
}

Compilation message (stderr)

knapsack.cpp: In function 'void Solve()':
knapsack.cpp:31:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 1; i <= a.size(); ++i)
      |                     ~~^~~~~~~~~~~
#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...