이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define MAXN 100010
#define MAXS 2010
using namespace std;
vector<ll> cnt[MAXN];
ll dp[MAXS],v[MAXN],w[MAXN],k[MAXN];
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll s,n,ans=0;
cin >> s >> n;
for (ll i=1;i<=n;i++)
cin >> v[i] >> w[i] >> k[i];
for (ll i=1;i<=s;i++)
{
priority_queue<pair<ll,ll> > q;
for (ll j=1;j<=n;j++)
{
if (i%w[j]!=0 || i/w[j]>k[j])
continue;
q.push({(i/w[j])*v[j],j});
}
ll cur=0;
while (!q.empty())
{
cur++;
if (cur*i>s)
break;
auto t=q.top();
q.pop();
cnt[t.second].push_back(i/w[t.second]);
}
}
for (ll i=1;i<=n;i++)
{
for (ll j=s;j>=0;j--)
{
for (ll l : cnt[i])
{
if (j+l*w[i]>s)
break;
dp[j+l*w[i]]=max(dp[j+l*w[i]],dp[j]+l*v[i]);
}
}
}
for (ll i=0;i<=s;i++)
ans=max(ans,dp[i]);
cout << ans;
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... |