#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));
}
};
int s, n;
ll dp[2010];
vector<pi>obj[2010];
void nhap(){
cin >> s >> n;
FOR(i, 1, n){
int v, w, k;
cin >> v >> w >> k;
obj[w].pb(C(v, k));
}
}
void solve(){
FOR(i, 1, s){
if(obj[i].size()) sort(obj[i].begin(), obj[i].end());
int limit = s / i;
FORD(j, obj[i].size() - 1, 0){
if(limit > obj[i][j].se){
limit -= obj[i][j].se;
FOR(cnt, 1, obj[i][j].se){
FORD(k, s, i){
maximize(dp[k], dp[k - i] + obj[i][j].fi);
}
}
}
else{
FOR(cnt, 1, limit){
FORD(k, s, i){
maximize(dp[k], dp[k - i] + obj[i][j].fi);
}
}
break;
}
}
}
ll ans = 0;
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... |