이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define file \
  freopen("time.in", "r", stdin);\
  freopen("time.out", "w", stdout)
#define OJudge(in,out) \
      freopen(in, "r", stdin);\
      freopen(out, "w", stdout)
#define FIn   \
  cin.tie(0); \
  cout.tie(0); \
  ios_base::sync_with_stdio(false)
const string IN = "input.txt";
const string OUT = "output.txt";
ll n,m,a,b,c;
int  tc;
int dp[2100][100100];
ll dp_ans[2100];
int v[100100], w[100100], k[100100];
void solve(){
    cin>>a>>n;
    for (int i = 0; i<n; i++){
        cin>>v[i]>>w[i]>>k[i];
    }
    ll rslt = 0;
    for(int i = 1; i<= a; i++){
        ll ans = 0;
        int idx = -1;
        for(int j = 0; j < n; j++){
            if(i - w[j] >= 0 && dp[i - w[j]][j] < k[j] && dp_ans[i - w[j]] + v[j] > ans){
                idx = j;
                ans = dp_ans[i - w[j]] + v[j];
            }
        }
        if (idx != -1) {
            for (int j = 0; j < n; j++) {
                dp[i][j] = dp[i - w[idx]][j];
            }
            dp[i][idx]++;
            dp_ans[i] = ans;
            rslt = max(rslt, ans);
        }
    }
    cout<<rslt;
}
int main() {
    FIn;
    //file;
    bool test = 0;
    if (test)
        cin>>tc;
    else tc = 1;
    for (int i = 1; i<=tc; i++){
        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... |