이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define cy cout<<"YES\n"
#define cn cout<<"NO\n"
#define cm cout<<-1<<"\n";
#define vl vector<ll>
#define vchar vector<char>
#define vvll vector<vector<ll>>
#define vvcr vector<vchar>
using namespace std;
const ll MOD=1e9+7;
ll times=0;
ll binepow(ll a,ll b,ll mod){
if(b==0){
return 1ll;
}
ll k=binepow(a,b/2,mod);
if(b%2==0){
times+=(k*k)/mod;
return (k*k)%mod;
}
else{
ll zz=(k*a)/mod;
ll newo=(k*a)%mod;
ll vv=(newo*k)/MOD;
times+=(vv+(zz*k)/mod+(zz*k)%MOD);
return (((k*a)%mod)*k)%mod;
}
}
////////////////////////////////////////////////////////
void solve(){
ll s,n;
cin>>s>>n;
vl w(n,0);
vl value(n,0);
vl items(n,0);
loop(i,0,n){
cin>>value[i]>>w[i]>>items[i];
}
vvll ans(n+1,vl(s+1,0));
ll final=0;
vl count(s+1,0);
loop(i,1,n+1){
fill(count.begin(),count.end(),0);
loop(j,1,s+1){
ans[i][j]=ans[i-1][j];
if(j-w[i-1]>=0){
if(count[j-w[i-1]]<items[i-1]){
if(ans[i][j]<(ans[i][j-w[i-1]]+value[i-1])){
count[j]=count[j-w[i-1]]+1;
ans[i][j]=ans[i][j-w[i-1]]+value[i-1];
}
}
}
final=max(final,ans[i][j]);
// cout<<ans[i][j]<<" ";
}
// cout<<endl;
}
cout<<final<<endl;
return;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
solve();
}
# | 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... |