OJ-Problems-Source/HDOJ/5310_autoAC.cpp
2016-09-13 04:54:18 +08:00

26 lines
471 B
C++

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int m,n,q,t,p;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&n,&m ,&p,&q);
int sum=0;
double op=q/m;
if(op<p)
{
sum+=(n/m)*q;
int pl=n%m;
sum+=min(p*pl,q);
cout<<sum<<endl;
}
else
cout<<p*n<<endl;
}
return 0;
}