Submission #1047885

#TimeUsernameProblemLanguageResultExecution timeMemory
1047885manhlinh1501Knapsack (NOI18_knapsack)C++17
17 / 100
4 ms3416 KiB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 1e5 + 5;

struct PRODUCT {
    int c, w, x;
    PRODUCT(int c = 0, int w = 0, int x = 0) : c(c), w(w), x(x) {}
};

int N, S;
PRODUCT a[MAXN];

namespace subtask {
    const int MAXN = 105;
    const int MAXV = 2e3 + 5;
    i64 dp[MAXN][MAXV];

    void solution() {
        for(int i = 1; i <= N; i++) {
            auto [c, w, x] = a[i];
            for(int j = 0; j <= S; j++) dp[i][j] = dp[i - 1][j];
            for(int z = 0; z <= x; z++) {
                for(int j = S; j >= w * x; j--)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - w * z] + 1LL * c * z);
            }
        }
        i64 ans = 0;
        for(int i = 1; i <= S; i++)
            ans = max(ans, dp[N][i]);
        cout << ans;
    }
}

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> S >> N;
    for(int i = 1; i <= N; i++) cin >> a[i].c >> a[i].w >> a[i].x;
    subtask::solution();
    return (0 ^ 0);
}

Compilation message (stderr)

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