#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 ll
signed main()
{
ios
int n, s; cin >> s >> n;
vector<vector<pair<int, int>>> dp(n, vector<pair<int, int>>(s + 1));
vector<int> v(n), w(n), k(n);
for(int i = 0; i < n; ++i) {
cin >> v[i] >> w[i] >> k[i];
}
auto max_self = [&](pair<int, int>& a, pair<int, int> b) {
if(a.first < b.first) {
a = b;
}
if(a.first == b.first && a.second > b.second) {
a = b;
}
};
int mx = 0;
for(int i = 0; i < n; ++i) {
for(int j = 0; j <= s; ++j) {
if(i) {
if(dp[i][j].first < dp[i - 1][j].first) {
dp[i][j] = {dp[i - 1][j].first, 0};
}
}
if(w[i] <= j && dp[i][j - w[i]].second < k[i]) {
max_self(dp[i][j],
{dp[i][j - w[i]].first + v[i], dp[i][j - w[i]].second + 1});
}
mx = max(mx, dp[i][j].first);
}
}
cout << mx << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |