이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr << #x << " => " << x << endl
#define all(x) x.begin(),x.end()
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int s,n;cin>>s>>n;
ll v[n+1],w[n+1],k[n+1];
for(int i=1;i<=n;i++) cin>>v[i]>>w[i]>>k[i];
ll dp[2][s+1];
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
for(int j=0;j<=s;j++)
{
int m=1;
dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][j]);
while(m<=k[i] && j+w[i]*m<=s)
{
dp[i%2][j+w[i]*m]=max(dp[i%2][j+w[i]*m],dp[(i+1)%2][j]+v[i]*m);
m++;
}
}
// for(int j=0;j<=s;j++) cout<<dp[i][j]<<' ';cout<<'\n';
}
cout<<dp[n%2][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... |