이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair <ll, ll>
#define foru(i,a,b) for (ll i = a; i <= b; i++)
#define ford(i,a,b) for (ll i = a; i >= b; i--)
#define N int(1e5 + 5)
#define M int(2e3 + 5)
#define MOD int(1e9 + 7)
#define base 311
int n, s;
ll dp[M];
vector <ii> w[M];
bool cmp(ii i, ii j)
{
return i.first > j.first;
}
int main()
{
// freopen("KNAPSACK.inp","r",stdin);
// freopen("KNAPSACK.out","w",stdout);
cin.tie(0) -> sync_with_stdio(0);
cout.tie(0);
cin >> s >> n;
foru(i, 1, n)
{
int v, u, k;
cin >> v >> u >> k;
w[u].push_back({v, k});
}
foru(i, 1, s)
{
dp[i] = -1;
sort(w[i].begin(), w[i].end(), cmp);
}
foru(i, 1, s)
{
int dem = 0;
for (ii j : w[i])
{
if (dem > s/i) break;
foru(z, 1, j.second)
{
if (dem > s/i) break;
ford(t, s, i)
if (dp[t - i] != -1)
dp[t] = max(dp[t], dp[t-i] + j.first);
dem++;
}
}
}
cout << *max_element(dp, dp+1+s);
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... |