0
点赞
收藏
分享

微信扫一扫

HDU 5310 Souvenir


Souvenir

 



Problem Description



p yuan and the price for a set of souvenirs if q yuan. There's m souvenirs in one set.There's n



Input



T (1≤T≤105), indicating the number of test cases. For each test case:There's a line containing 4 integers n,m,p,q (1≤n,m,p,q≤104).



Output



For each test case, output the minimum cost needed.



Sample Input



2 1 2 2 1 1 2 3 4



Sample Output



1 3

Hint

For the first case, Soda can use 1 yuan to buy a set of 2 souvenirs.

For the second case, Soda can use 3 yuan to buy a souvenir.




#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

using namespace std;

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        __int64 sum = 0;
        int n,m,p,q;
        scanf("%d%d%d%d",&n,&m,&p,&q);
        if(p*m<=q)
        {
            printf("%d\n",p*n);
        }
        else
        {
            sum = (n/m)*q;
            n = n%m;
            if(n*p<q)
            {
                printf("%I64d\n",sum+n*p);
            }
            else
            {
                printf("%I64d\n",sum+q);
            }
        }
    }
    return 0;
}



举报

相关推荐

0 条评论