제출 #780187

#제출 시각아이디문제언어결과실행 시간메모리
780187andecaandeciKnapsack (NOI18_knapsack)C++17
73 / 100
1066 ms316 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MAXN = 1e5 + 5;
const ll MAXT = 2e3 + 5;

ll n, t, li, ei, ki, dp[MAXT];

void update(ll a, ll b) {
  // {Spread, Energi}
  for (int i = t; i >= 0; --i)
  {
    if (i < b)
    {
      break;
    }
    dp[i] = max(dp[i], dp[i-b] + a);
  }
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cin >> t >> n;

  for (int i = 0; i < n; ++i)
  {
    cin >> li >> ei >> ki;
    ki = min(ki, t / ei);

    while(ki--) {
      update(li, ei);
    }
  }

  cout << dp[t] << "\n";
  return 0;
}
#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...