# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
439537 | asc | Baloni (COCI15_baloni) | Java | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Baloni {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int numOfBalloons=sc.nextInt();
Integer[] arrayOfBalloons=new Integer[numOfBalloons];
for (int i=0;i<numOfBalloons;i++){
arrayOfBalloons[i]=sc.nextInt();
}
List<Integer> listOfBalloons= new ArrayList<>(Arrays.asList(arrayOfBalloons));
int numOfArrow=0;
while (listOfBalloons.isEmpty()==false){
int currBalloonsIndex=0;
List<Integer> groupingBalloons= new ArrayList<>();
groupingBalloons.add(listOfBalloons.get(currBalloonsIndex));
for (int i = 1; i < listOfBalloons.size(); i++) {
if (groupingBalloons.get(groupingBalloons.size()-1) - listOfBalloons.get(i) == 1) {
groupingBalloons.add(listOfBalloons.get(i));
}
}
Integer[] grouping= new Integer[groupingBalloons.size()];
for (int i=0;i<groupingBalloons.size();i++){
grouping[i]=groupingBalloons.get(i);
}
for (Integer x:grouping) {
listOfBalloons.remove(x);
}
numOfArrow+=1;
}
System.out.println(numOfArrow);
}
}