Submission #1284762

#TimeUsernameProblemLanguageResultExecution timeMemory
1284762blackscreen1Knapsack (NOI18_knapsack)C++20
100 / 100
249 ms246424 KiB
#include <bits//stdc++.h>
using namespace std;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define iloop_(m, h, g) for (auto i = m; i != h; i += g)
#define jloop_(m, h, g) for (auto j = m; j != h; j += g)
#define kloop_(m, h, g) for (auto k = m; k != h; k += g)
#define lloop_(m, h, g) for (auto l = m; l != h; l += g)
#define getchar_unlocked _getchar_nolock // comment before submission
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define pllll pair<pll, pll>
#define vll vector<ll>
#define qll queue<ll>
#define dll deque<ll>
#define pqll priority_queue<ll>
#define gll greater<ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  ll n, m, v, w, s;
  cin >> n >> m;
  priority_queue<pll> a[n];
  vector<pll> vc;
  iloop(0, m) {
    cin >> v >> w >> s;
    a[w-1].push({v, s});
  }
  iloop(0, n) {
    ll ctop = -1, ccnt = 0;
    jloop(0, floor(n/(i+1))) {
      if (ccnt == 0) {
        if (a[i].size() == 0) break;
        ctop = a[i].top().first;
        ccnt = a[i].top().second;
        a[i].pop();
      }
      ccnt--;
      vc.push_back({ctop, i+1});
    }
  }
  ll dp[n+1][vc.size()+1], ans = 0;
  iloop(0, n+1) {
    jloop(0, (ll)vc.size()+1) {
      if ((!i) || (!j)) dp[i][j] = 0;
      else if (vc[j-1].second > i) dp[i][j] = dp[i][j-1];
      else dp[i][j] = max(dp[i][j-1], dp[i-vc[j-1].second][j-1] + vc[j-1].first);
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
}
#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...