-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcertTickets.java
More file actions
34 lines (32 loc) · 1.02 KB
/
ConcertTickets.java
File metadata and controls
34 lines (32 loc) · 1.02 KB
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
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public class ConcertTickets{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numTickets = sc.nextInt();
int numCustomers = sc. nextInt();
ArrayList<Integer> price = new ArrayList<Integer>();
int[] maxPrice = new int[numCustomers];
for(int i = 0; i<numTickets; i++){
price.add(sc.nextInt());
}
for(int i = 0; i<numCustomers; i++){
maxPrice[i] = sc.nextInt();
}
Collections.sort(price);
for(int i = 0; i<numCustomers; i++){
Iterator<Integer> it = price.iterator();
Integer x = -1;
while(it.hasNext()) {
if(it.next()>maxPrice[i]){
System.out.println(x);
it.remove();
continue;
}
x = it.next();
}
}
}
}