Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <stdio.h>
using namespace std;
int main() {
int n, m, a, b, res = 1e9;
scanf("%d%d%d%d", &n, &m, &a, &b);
for(int i = 0; i <= 1000; i++)
if(i * m + j >= n)
res = min(res, i * b + max(0, n - i * m) * a);
printf("%d\n", res);
return 0;
}
Copy The Code &
Try With Live Editor
Input
6 2 1 2
Output
6
Demonstration
Codeforces Solution-Cheap Travel-Solution in C, C++, Java, Python