#pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx, avx2, fma")
#include <bits/stdc++.h>
using namespace std;
#define speedup cin.tie(0)->sync_with_stdio(0)
#define bitcount(x) __builtin_popcountll(x)
#define lla(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define Tp template<class T>
#define pb push_back
#define arr array
Tp using vc = vector<T>;
using pii = pair<int,int>;
using ld = long double;
using ll = long long;
const ll mod = 998244353, N = 501, inf = 1e18;;
inline void solve() {
int n, s; cin >> s >> n;
vc<ll> c(n + 1), w(n + 1), cnt(n + 1);
for(int i = 1; i <= n; i++) cin >> c[i] >> w[i] >> cnt[i];
vc<ll> dp(s + 1, -inf); dp[0] = 0;
for(int i = 1; i <= n; i++) {
while(w[i] <= s && cnt[i]) {
for(int x = s; x >= w[i]; x--)
dp[x] = max(dp[x], dp[x - w[i]] + c[i]);
w[i] <<= 1;
c[i] <<= 1;
cnt[i] >>= 1;
}
} cout << *max_element(all(dp)) << '\n';
}
signed main() {
speedup;
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... |