Dr. Ryan Stone has been trying to fix the communications equipment at the Hubble Space telescope when the crew of the Explorer Shuttle receive the news of a debris field headed their way. She now needs to get all her “N” instruments back to the shuttle as soon as possible. But at the most, she can carry only “M” instruments with her at a time, and it takes her exactly “T”” minutes to go between the telescope and the shuttle.

What is the minimum amount of time she needs to get all her instruments back into the shuttle? Assume that she is at the shuttle while receiving the news.

Input Format:

The first line consists of the number of tests cases, C.

Each of the next C lines consist of 3 integers: N, M and T.

The first line consists of the number of tests cases, C.

Each of the next C lines consist of 3 integers: N, M and T.

Output Format:

For each test case, output the least amount of time she needs to transfer all her instruments back to the shuttle.

For each test case, output the least amount of time she needs to transfer all her instruments back to the shuttle.

Constraints

1 <= C <= 1000

1 <= N, M, T <= 100

time limit: 4 sec

memory limit: 256 mb

1 <= N, M, T <= 100

time limit: 4 sec

memory limit: 256 mb

Sample Input:

```
1
3 2 10
```

Sample Output:

```
40
```

Explanation:

Dr Stone takes 10 minutes to get from the shuttle to the telescope,

then she takes 10 minutes to carry 2 of the instruments back,

then she takes 10 minutes to get back to the telescope,

and then she takes 10 minutes to carry the remaining 1 instrument back.

Dr Stone takes 10 minutes to get from the shuttle to the telescope,

then she takes 10 minutes to carry 2 of the instruments back,

then she takes 10 minutes to get back to the telescope,

and then she takes 10 minutes to carry the remaining 1 instrument back.

import java.util.Scanner; /** * * @author VIK */ public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int c = sc.nextInt(); int cost = 0; int[] arr = new int[c]; int i = 1; while (i <= c) { cost = 0; int n = sc.nextInt(); int m = sc.nextInt(); int t = sc.nextInt(); if (n > m) { cost = 2 * t * ((n / m)); if (n % m != 0) { cost += 2 * t; } } else { cost = 2 * t; } arr[i - 1] = cost; i++; } for (i = 0; i < arr.length; i++) { if (i != c - 1) { System.out.println(arr[i]); } else { System.out.print(arr[i]); } } } }

## No comments :

## Post a Comment