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>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
using ll = long long;
int mod = (ll)1e9 + 7;
#define PI acos(-1)
typedef pair<int, int> pairs;
const int INF = 1e9 + 1;
const int N = 2e5 + 100;
const double eps = 1e-7;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <typename XPAX>
void ckma(XPAX &x, XPAX y) {
x = (x < y ? y : x);
}
template <typename XPAX>
void ckmi(XPAX &x, XPAX y) {
x = (x > y ? y : x);
}
void solve() {
int S, n;
cin >> S >> n;
VV<array<int, 2>> g(S + 1);
forn(i, n) {
int a, b, c;
cin >> a >>b >> c;
g[b].push_back({a, c});
}
V<int> dp(S + 1, -INF);
dp[0] = 0;
for(int i = 1;i <= S;++i) {
if(!g[i].size())continue;
sort(g[i].rbegin(), g[i].rend());
int x = i;
for(auto c : g[i]) {
if(x > S)
break;
for(int j = 0;j < c[1] && x <= S;x += i, ++j) {
for(int k = S;k >= i;--k)
ckma(dp[k], dp[k - i] + c[0]);
}
}
}
//debug(dp);
cout << *max_element(all(dp)) << '\n';
}
void test_case() {
int t;
cin >> t;
forn(p, t) {
//cout << "Case #" << p + 1 << ": ";
solve();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |