pblpfr | 2015-07-26 18:30:54
Author
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int t,n,m,p,q,sum;
scanf("%d",&t);
while (t--)
{
scanf("%d%d%d%d",&n,&m,&p,&q);
sum=n*p;
while (n>0)
{
if (n>m)
{
if (q<m*p) sum=sum-m*p+q;
}
else
{
if (q<n*p) sum=sum-n*p+q;
}
n-=m;
}
printf("%d\n",sum);
}
return 0;
}