이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
#endif
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define lim 100000
using namespace std;
const int mod=1000000007ll;
void solve(){
int s,n;
cin>>s>>n;
int dp[s+1];
memset(dp,0,sizeof(dp));
dp[0]=0;
for(int i=0;i<n;i++){
int v,w,k;
cin>>v>>w>>k;
int sv=v,sw=w;
//cerr<<k<<" "<<w<<" "<<(s/w)<<"\n";
k=min(k,(s/w));
for(int t=s-w;0<=t;t--){
//cerr<<s<<" "<<t+w<<" "<<t<<"\n";
dp[t+w]=max(dp[t+w],dp[t]+v);
//cerr<<v<<"\n";
}
k--;
//cerr<<"ok "<<k<<"\n";
for(int j=1;j<=k;k-=j,j<<=1,w<<=1,v<<=1){
for(int t=s-w;0<=t;t--){
dp[t+w]=max(dp[t+w],dp[t]+v);
//cerr<<v<<"\n";
}
}
sv*=k,sw*=k;
for(int t=s-sw;0<=t;t--){
dp[t+sw]=max(dp[t+sw],dp[t]+sv);
}
}
cout<<*max_element(dp,dp+s+1);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
int t=1;
//cin>>t;
while (t--)
{
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... |