이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cout<<":["<<x<<"XE]"<<endl;
#define debug2(x,y) cout<<":["<<x<<" "<<y<<"XE]"<<endl;
#define _ ios_base::sync_with_stdio(false);
#define mod 1000000007
#define mod2 998244353
#define inf LLONG_MAX
#define yes cout << "YES\n"
#define yes2 cout << "Yes\n"
#define no cout << "NO\n"
#define no2 cout << "No\n"
ll n,s;
ll v[100005];
ll w[100005];
ll q[100005];
ll dp[100005][2005];
ll sol(ll idx,ll sum)
{
if(idx>n){
return 0;
}
if(dp[idx][sum]!=-1)return dp[idx][sum];
ll x=0,y=0;
for(int i=1;i<=q[idx];i++){
if(sum+i*w[idx]>s)break;
x=sol(idx+1,sum+i*w[idx])+v[idx]*i;
}
y=sol(idx+1,sum);
return dp[idx][sum]=max(x,y);
}
int main()
{_
// freopen("feast.in", "r", stdin);
// freopen("feast.out", "w", stdout);
ll t=1;
//cin>>t;
///CHECK FROM HERE***
while(t--){
//ll n,s;
cin>>s>>n;
for(int i=1;i<=n;i++){
cin>>v[i]>>w[i]>>q[i];
}
memset(dp,-1,sizeof dp);
cout<<sol(1,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... |