-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcostOfBalloons.java
More file actions
39 lines (33 loc) · 1.16 KB
/
Copy pathcostOfBalloons.java
File metadata and controls
39 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
// time = O(t*n)
class TestClass {
public static void main(String args[] ) throws Exception {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- >0){
int greenCost = sc.nextInt();
int purpleCost = sc.nextInt();
int n = sc.nextInt();
int[][] participants = new int[n][2];
for (int i = 0; i < n; i++) {
participants[i][0] = sc.nextInt();
participants[i][1] = sc.nextInt();
}
int greenFirstCost = 0;
int purpleFirstCost = 0;
for (int i = 0; i < n; i++) {
if (participants[i][0] == 1) {
greenFirstCost += greenCost;
purpleFirstCost += purpleCost;
}
if (participants[i][1] == 1) {
greenFirstCost += purpleCost;
purpleFirstCost += greenCost;
}
}
System.out.println(Math.min(greenFirstCost, purpleFirstCost));
}
}
}