This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,tune=native")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
//template <typename T>
//using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int,int> pii;
const int arr = 2e3+1;
const ll mod = 1e9+7;
const ll maxv = 1e18+1;
#define int long long
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define no "NO\n"
#define yes "YES\n"
#define ld long double
#define mat vector<vector<ll>>
int s, n, dp[30001];
pair<pii, int> a[arr];
vector<pii> tmp;
int cnt[arr];
bool cmp(pair<pii, int> c, pair<pii, int> d){
return (c.fi.fi > d.fi.fi);
}
void read(){
cin >> s >> n;
for(int i = 1; i <= n; ++i){
cin >> a[i].fi.fi >> a[i].fi.se >> a[i].se;
}
sort(a+1, a+n+1, cmp);
for(int i = 1; i <= n; ++i){
int j = 1;
for(; j <= min(a[i].se, (s/a[i].fi.se)-cnt[a[i].fi.se]); ++j)
tmp.pb(a[i].fi);
cnt[a[i].fi.se] += j-1;
}
}
void solve(){
int ans = 0;
for(auto id : tmp){
//cout << id.fi << " " << id.se << endl;
int v = id.fi, w = id.se;
for(int j = s; j >= w; --j){
dp[j] = max(dp[j], dp[j-w]+v);
ans = max(ans, dp[j]);
}
}
cout << ans;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
read();
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... |