이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define file "main"
#define maxn (int) 3e6 + 5
#define ll long long
#define pii pair<ll, int>
#define fi(i, a, b) for(int i = a; i <= b; i ++)
#define fid(i, a, b) for(int i = a; i >= b; i --)
using namespace std;
int S, n, N;
pii a[maxn];
ll dp[2005];
int main() {
    freopen(file".inp", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> S >> n;
    fi(i, 1, n) {
        int v, w, k; cin >> v >> w >> k;
        for(int tmp = 1; tmp <= k; tmp *= 2) {
            int nw_v = v * tmp, nw_w = w * tmp;
            if(nw_w <= S) a[++N] = { nw_v, nw_w };
            k -= tmp;
        }
        if(k) {
            int nw_v = v * k, nw_w = w * k;
            if(nw_w <= S) a[++N] = { nw_v, nw_w };
        }
    }
    memset(dp, -0x3f, sizeof dp);
    dp[0] = 0;
    fi(i, 1, N) {
        fid(j, S, a[i].second) {
            dp[j] = max(dp[j], dp[j - a[i].second] + a[i].first);
        }
    }
    cout << *max_element(dp + 0, dp + S + 1);
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen(file".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |