Submission #1322659

#TimeUsernameProblemLanguageResultExecution timeMemory
1322659trandinhnhatKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms2744 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define str string
#define ch char
#define task ""
#define pb push_back
#define ii pair<ll,ll>
#define iii pair <ll, ii>
#define fi first
#define se second
using namespace std;

template<class X, class Y>
bool maximize(X &x, const Y &y) { return (x < y) ? (x = y, true) : false; }

template<class X, class Y>
bool minimize(X &x, const Y &y) { return (x > y) ? (x = y, true) : false; }

const ll mod = 1e9 + 7;
const ll N = 1e6 + 5;
const ll inf = LLONG_MAX;
const ll SHIFT = 1e6;

ll w[N], v[N], a[N], dp[N];
ll n, S;

void sub1();
void sub2();
void sub3();

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    cin >> S >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> v[i] >> w[i] >> a[i];
    }
    for (ll i = 1; i <= n; i++) {
        for (ll j = S; j >= w[i]; j--) {
            for (ll k = 1; k <= a[i]; k++) {
                if (j - w[i] * k >= 0) {
                    dp[j] = max(dp[j], dp[j - w[i] * k] + v[i] * k);
                }
                else {
                    break;
                }
            }
        }
    }
    cout << dp[S];
    return 0;
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...