-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCookies.java
More file actions
37 lines (35 loc) · 985 Bytes
/
Cookies.java
File metadata and controls
37 lines (35 loc) · 985 Bytes
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
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int sweetness=sc.nextInt();
ArrayList<Integer> list=new ArrayList<>();
while(sc.hasNext())
{
if(sc.hasNextInt())
{
list.add(sc.nextInt());
}
else
{
sc.next();
}
}
int count=0;
Collections.sort(list);
while(list.size()>2 && list.get(0)<sweetness)
{
int change=list.get(0)+2*list.get(1);
list.remove(0);
list.remove(1);
list.add(change);
Collections.sort(list);
count++;
}
System.out.println(count);
}
}