이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define endl '\n'
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 37
#endif
inline void solve(){
    ll S, n;
    cin >> S >> n;
    vector<pair<ll, ll> > items;
    for(ll i = 0; i < n; ++i) {
        ll val, w, cnt;
        cin >> val >> w >> cnt;
        cnt = min(cnt, S);
        while(cnt--) {
            items.push_back({val, w});
        }
    }
    const ll inf = 1e18 + 42;
    vector<ll> dp(S + 1, -inf);
    dp[0] = 0;
    for(auto [item_val, item_w] : items) {
        for(ll W = S; W >= item_w; --W) {
            dp[W] = max(dp[W], dp[W - item_w] + item_val);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << '\n';
}
 
signed main(){
    #ifdef LOCAL
    freopen("test.in", "r", stdin);
    freopen("err.txt", "w", stderr);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); 
    // signed t; cin >> t; while(t--)
        solve();
}
| # | 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... |