-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prblm 21
45 lines (40 loc) · 829 Bytes
/
Prblm 21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n,m,a,b;
cin>>n>>m>>a>>b;
if(n/m==0)
{
long long int arr[4];
arr[0]=((n/m)*b)+((n%m)*a);
arr[1]=((n/m)*b)+((n%m)*b);
arr[2]=b;
arr[3]=n*a;
sort(arr,arr+4);
cout<<arr[0]<<endl;
}
else
{
if(n%m<=m)
{
long long int arr[4];
arr[0]=((n/m)*b)+((n%m)*a);
arr[1]=((n/m)*b)+((n%m)*b);
arr[2]=((n/m)+1)*b;
arr[3]=n*a;
sort(arr,arr+4);
cout<<arr[0]<<endl;
}
else
{
long long int arr[3];
arr[0]=((n/m)*b)+((n%m)*a);
arr[1]=((n/m)*b)+((n%m)*b);
arr[2]=n*a;
sort(arr,arr+3);
cout<<arr[0]<<endl;
}
}
return 0;
}