-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA 1207 - There Are Two Types Of Burgers.java
67 lines (58 loc) · 2.25 KB
/
A 1207 - There Are Two Types Of Burgers.java
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[][] data = new int[n*2][3];
for (int i = 0; i < data.length; i++) {
if (i % 2 == 0) {
for (int j = 0; j < 3; j++) {
data[i][j] = input.nextInt();
}
} else {
for (int j = 0; j < 2; j++) {
data[i][j] = input.nextInt();
}
}
}
boolean a = true;
int hasil,count = 0;
for (int i = 1; i < data.length;) {
hasil = 0;
if (i % 2 == 1) {
for (int j = 0; j < 1; j++) {
a = data[i][j] > data[i][j + 1];
}
i--;
} else {
if (a == true) {
while (data[i][0] >= 2 && (data[i][1] >= 1 || data[i][2] >= 1)) {
if (data[i][0] >= 2 && data[i][1] >= 1) {
hasil = hasil + data[i + 1][0];
data[i][0] -= 2;
data[i][1]--;
} else if (data[i][0] >= 2 && data[i][2] >= 1) {
hasil = hasil + data[i + 1][1];
data[i][0] -= 2;
data[i][2]--;
}
}
} else if (a == false) {
while (data[i][0] >= 2 && (data[i][1] >= 1 || data[i][2] >= 1)) {
if (data[i][0] >= 2 && data[i][2] >= 1) {
hasil = hasil + data[i + 1][1];
data[i][0] -= 2;
data[i][2]--;
} else if (data[i][0] >= 2 && data[i][1] >= 1) {
hasil = hasil + data[i + 1][0];
data[i][0] -= 2;
data[i][1]--;
}
}
}
i = i + 3;
System.out.println(hasil);
}
}
}
}