Submission #1003664

#TimeUsernameProblemLanguageResultExecution timeMemory
1003664ypratikKnapsack (NOI18_knapsack)C++17
37 / 100
1048 ms67000 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;
    for (int i = 0; i < n; ++i)
    {
        int x, y, z;
        cin >> x >> y >> z;
        while (z--)
        {
            a.push_back({x, y});
        }
    }
    vector<int> dp(s + 1, -INF);
    dp[0] = 0;

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

    int ans = 0;
    for (int i = 0; i < s + 1; ++i)
    {
        ans = max(ans, dp[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:28: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]
   28 |     for (int i = 0; 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...