This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int gen(int a, int b) {return (ll)rng() % (b - a + 1) + a;}
#define int long long
signed main()
{
ios
int s, n; cin >> s >> n;
vector<vector<int>> a(n, vector<int>(3));
for(vector<int>& row : a) {
for(int& x : row) {
cin >> x;
}
}
vector<vector<pair<int, int>>> dp(n + 1,
vector<pair<int, int>>(s + 1));
for(int i = 1; i <= n; ++i) {
for(int j = 0; j <= s; ++j) {
dp[i][j].first = max(dp[i][j].first, dp[i - 1][j].first);
if(j >= a[i - 1][1] && dp[i][j - a[i - 1][1]].second < a[i - 1][2]) {
int after = dp[i][j - a[i - 1][1]].first + a[i - 1][0];
if(dp[i][j].first < after) {
dp[i][j].first = after;
dp[i][j].second = dp[i][j - a[i - 1][1]].second + 1;
}
}
}
}
int mx = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 0; j <= s; ++j) {
mx = max(mx, dp[i][j].first);
}
}
cout << mx << '\n';
}
# | 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... |