이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ull unsigned long long
#define ll long long
#define SPEED \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
using namespace std;
const int N = 1000 + 13;
const int maxa = 1e6 + 13;
const ll mod = 998244353;
using tp = tuple<ll, ll, ll>;
void prestart() {}
ll dp[maxa];
void start()
{
int s, n;
cin >> s >> n;
vector<tp> a;
forn(i, n) {
ll v, w, k;
cin >> v;
cin >> w;
cin >> k;
a.push_back({v, w, k});
}
sort(a.begin(), a.end(), [](tp a, tp b) {
ll f = get<0>(a) * get<1>(b);
ll m = get<0>(b) * get<1>(a);
if (f == m) return get<1>(b) < get<1>(a);
return get<0>(a) * get<1>(b) < get<0>(b) * get<1>(a);
});
for (int i = 0; i < n; i++)
{
ll v = get<0>(a[i]);
ll w = get<1>(a[i]);
ll k = get<2>(a[i]);
for (int j = s; j >= 0; j--)
{
ll l = min(k, j / w);
dp[j] = max(dp[j], dp[j - w * l] + v * l);
}
}
cout << dp[s] << "\n";
}
signed main()
{
SPEED;
int t = 1;
prestart();
// cin >> t;
while (t--)
{
start();
}
}
# | 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... |