fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,m,a,b;
  6. cin>>n>>m>>a>>b;
  7. int final=0,dp[n+1];
  8. dp[0]=0;
  9. for(int i=1;i<=n;i++){
  10. if(i>=m)
  11. dp[i] = min(dp[i-1]+a,dp[i-m]+b);
  12. else dp[i]=min(dp[i-1]+a,b);
  13. //cout<<dp[i]<<" ";
  14. }
  15. cout<<dp[n];
  16. return 0;
  17. }
Success #stdin #stdout 0s 3100KB
stdin
5 2 2 3
stdout
8