mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
6d0ead9b6a
5300-5399
26 lines
471 B
C++
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;
|
|
}
|