#include<bits/stdc++.h>
using namespace std;
template <typename T> bool maximize(T &res, const T &val){if(res < val) return res = val, true; return false;}
template <typename T> bool minimize(T &res, const T &val){if(res > val) return res = val, true; return false;}
#define ll long long
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for(int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for(int i = 0, _n = (n); i < _n; i++)
#define C make_pair
#define MASK(i) (1LL << (i))
#define TURN_ON(i, x) ((x) | MASK(i))
#define TURN_OFF(i, x) ((x) & ~MASK(i))
#define RE(i, x) ((x) ^ MASK(i))
const ll mod = 1e9 + 7;
const ll INF = 1e15;
const int maxn = 1e5 + 5;
typedef pair<int, int> pi;
typedef pair<int, pair<int,int>> pii;
typedef pair<ll, ll> pl;
typedef pair<ll, pair<ll,ll>>pll;
struct edge{
int u,v,w;
edge(int u = 0, int v = 0, int w = 0)
{
this->u = u;
this->v = v;
this->w = w;
}
};
struct matrix{
ll val[3][3];
matrix(){
memset(val, 0, sizeof(val));
}
};
ll n, s, dp[2010], ans;
vector<pl>a[2010];
void nhap(){
cin >> s >> n;
FOR(i, 1, n){
int v, w, k; cin >> v >> w >> k;
a[w].pb(C(v, k));
}
}
void solve(){
FOR(i, 1, s){
if(a[i].size()) sort(a[i].begin(), a[i].end(), greater<pi>());
int cnt = s / i;
for(pi x: a[i]){
if(x.se >= cnt){
FOR(tmp, 1, cnt) FORD(j, s, i)
maximize(dp[j], dp[j - i] + x.fi);
break;
}
else{
FOR(tmp, 1, x.se) FORD(j, s, i)
maximize(dp[j], dp[j - i] + x.fi);
cnt -= x.se;
}
}
}
FOR(i, 1, s) maximize(ans, dp[i]);
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
nhap();
solve();
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... |