37 lines
1.0 KiB
Plaintext
37 lines
1.0 KiB
Plaintext
|
import java.util.Scanner;
|
||
|
import java.util.List;
|
||
|
import java.util.ArrayList;
|
||
|
|
||
|
public class plakatowanie{
|
||
|
|
||
|
public static void main(String[] args){
|
||
|
|
||
|
Scanner in = new Scanner(System.in);
|
||
|
System.out.println("Number of buildings: ");
|
||
|
int liczba_budynkow = in.nextInt();
|
||
|
System.out.println("buildings: ");
|
||
|
int budynki[][] = new int[liczba_budynkow][2];
|
||
|
|
||
|
for (int i = 0; i < liczba_budynkow;i++){
|
||
|
for (int j = 0; j < 2; j++){
|
||
|
budynki[i][j] = in.nextInt();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
List<Integer> plakaty = new ArrayList<>();
|
||
|
int wynik = 0;
|
||
|
|
||
|
|
||
|
for (int i = 0; i < liczba_budynkow; i++) {
|
||
|
while ((plakaty.size() > 0) && (plakaty.get(plakaty.size()-1) > budynki[i][1])){
|
||
|
plakaty.remove(plakaty.size()-1);
|
||
|
}
|
||
|
|
||
|
if ((plakaty.size() == 0) || (plakaty.get(plakaty.size()-1) < budynki[i][1])){
|
||
|
plakaty.add(budynki[i][1]);
|
||
|
wynik+=1;
|
||
|
}
|
||
|
}
|
||
|
System.out.println(wynik);
|
||
|
}
|
||
|
}
|