This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using LL = long long;
int main() {
  cin.tie(nullptr)->ios_base::sync_with_stdio(false); 
  LL s, n;
  cin >> s >> n;
  vector <LL> weight (n), val (n), copy (n);
  for (int i = 0; i < n; i++) cin >> val[i] >> weight[i] >> copy[i];
  vector <LL> dp (s + 1), ndp (s + 1);
  for (LL i = 1; i <= n; i++) {
    for (LL j = s; j >= 0; j--) {
      ndp[j] = dp[j];
      for (LL k = 1; k <= copy[i - 1] and k * weight[i - 1] <= s and k * weight[i - 1] <= j; k++) {  
        ndp[j] = max (ndp[j], dp[j - k * weight[i - 1]] + k * val[i - 1]);
      }
    }
    swap (dp, ndp);
  }
  cout << *max_element (all (dp)) << '\n';
  return 0;
}
| # | 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... |