-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpizza.java
47 lines (45 loc) · 878 Bytes
/
pizza.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
import java.io.*;
public class pizza{
public static void main(String[] args)throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int a[]=new int[3];
int t=Integer.parseInt(str);
for(int i=0;i<t;i++){
String x=br.readLine();
if(x.equals("1/4")){
a[0]++;
}
else if(x.equals("1/2")){
a[1]++;
}
else{
a[2]++;
}
}
if(a[0]<=a[2]){
a[0]=0;
if(a[1]%2==0){
a[1]=a[1]/2;
}else{
a[1]=a[1]/2 +1;
}
}else{
a[0]=a[0]-a[2];
if(a[1]%2==0){
a[1]=a[1]/2;
}else{
a[1]=a[1]/2 +1;
if(a[0]<=2){
a[0]=0;
}else{
a[0]-=2;
}
}
}
if(a[0]!=0)
a[0]=a[0]/4+1;
int pizza=a[0]+a[1]+a[2]+1;
System.out.println(pizza);
}
}