Submit | All submissions | Best solutions | Back to list |
GAMARENA - GAMING ARENA |
Elgin and Hajee are planning to conduct gamindrome next day. As they have to connect all the computers, they need LAN cables, hubs and wireless routers. They went to Richi street to purchase them. Unexpectedly hub was not available in any shop.
Any LAN cable can connect two computers. Any wireless router can connect at most âkâ number of computers. Any computer can be connected to at most one LAN cable and at most one wireless network. If a computer is connected to both LAN and wireless, the connections get automatically bridged.
They have n computers and their aim is to connect all the computers with minimum cost. So they have to buy minimum number of LAN cables and wireless routers.
The cost of of buying one LAN cable is L and the cost of buying one wireless router is W.
Given n, k, L and W find the minimum cost needed to connect all the computers.
Input
The first line contains an integer t, the number of test cases. Each test case consists 4 integers n, k, L and W as defined above.
Output
For each test case find the minimum cost to connect all the computers.
Constraints
1 <= t <= 1000
1 <= n <= 1000
2 <= k <= 1000
1 <= L <= 1000
1 <= W <= 1000
Example
Input: 9 1 4 8 6 10 2 5 8 5 4 9 9 2 5 2 6 7 3 3 6 3 3 3 5 6 4 7 2 10 4 2 7 5 3 10 8 Output: 0 57 18 2 18 5 11 20 26
Added by: | cegprakash |
Date: | 2012-05-12 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: BF GOSU |
hide comments
2013-01-24 18:32:55 cegprakash
Tosif Khan : Your code must be tricky! |
|
2013-01-24 18:16:46 Tosif Khan
all given test cases are passing, still wrong ans, can anybody give any tricky test case |
|
2013-01-24 15:47:46 cegprakash
archit: one computer can be connected to atmost 1 lan cable and atmost 1 wireless network |
|
2013-01-24 15:45:24 MITIANS
@cegprakash: why shouldnt be it connectd like 1-1-1-1-1-1-1-1-1 ,cost is just 45 |
|
2013-01-24 15:45:14 Archit Mittal
for 10 4 2 7 if we use 1 router and 6 lan then we get 19 |
|
2013-01-24 15:19:12 cegprakash
10 2 5 8 You have to connect 10 computers. Assume that '~' is a wireless router and '-' as a lan cable. 1-(1~1)-(1~1)-(1~1)-(1~1)-1 You can connect the computers this way |
|
2013-01-24 14:54:43 Vignesh
can you give a brief explanation for one of the test cases above? |
|
2013-01-24 14:52:31 cegprakash
@chirag : use class class_name do not use public class. the "class_name" can be anything. @prateek : The sample test cases are correct Last edit: 2013-01-24 14:53:17 |
|
2013-01-24 14:48:40 chirag
what should be the name of java main Class ?? |
|
2013-01-24 14:44:46 Prateek Mittal
i thnk so answer of 2nd test cases sud be 25??? sdmin plz reply |