#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pii pair<int, int>
#define ld long double
#define all(v) v.begin(), v.end()
using namespace std;
const int oo = 1e18 + 9;
const int MAX = 1e6 + 6;
int MOD = 998244353;
void solve(){
int s, n; cin >> s >> n;
vector<pii> V[s + 1];
for(int i = 1; i <= n; i++){
int v, w, k; cin >> v >> w >> k;
V[w].push_back({v, k});
}
vector<int> dp(s + 1, 0);
for(int i = 1; i <= s; i++){
sort(all(V[i]));
reverse(all(V[i]));
vector<int> v;
for(auto a : V[i]){
while(a.second && v.size() < s / i){
v.push_back(a.first);
a.second--;
}
}
for(int a : v){
for(int j = s - i; j >= 0; j--){
dp[j + i] = max(dp[j + i], dp[j] + a);
}
}
}
cout << dp[s] << '\n';
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) 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... |