Souveniraccepts:901submissions:2743Time limit:2000/1000 MS (java/others)Memory limit:262144/262144 K (java/others)Problem Description
Today is the 1st anniversary of Bestcoder. Soda, the contest manager, wants to buy a souvenir for each contestant. You can buy the souvenir one by one or set by set in the shop. The price of a souvenir isp p yuan and the price for a set of souvenirs if& nbsp q q yuan. There ' S m< Span class= "Strut bottom" >m souvenirs in one Set.
There ' s nN contestants in the contest today. Soda wants to know the minimum cost needed to buy a souvenir for each contestant.
Input
There is multiple test cases. The first line of input contains an integerTT (1 \le T \le 10^5) (1≤t≤1 0 ? 5 ??
There ' s a line containing 4 integersN, M, p, qN,M,P,Q(1 \le N, M, p, Q \le 10^4)(1≤n,m,p,q≤10? ) 4?? ).
Output
For each test case, the output of the minimum cost needed.
Sample Input
21 2 2 11 2 3 4
Sample Output
13
Hintfor 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.
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 intMain ()6 {7 intt,n,m,p,q,i,j,k;8scanf"%d",&T);9 while(t--)Ten { Onescanf"%d %d%d%d",&n,&m,&p,&q); A if((Double) p<= (Double) q/m) - { -printf"%d\n"Np); the } - Else - { - intx=0; + for(i=1;; i++) - { +x=x+m; A if(x>=N) at Break; - } -printf"%d\n", Min (I*q, (i-1) *q+ (n (x-m)) *p)); - } - } - return 0; in}
View Code
Bestcoder 1st Anniversary ($) 1001 Souvenir