Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class ConcertTickets {
- static class InputReader {
- BufferedReader reader;
- StringTokenizer tokenizer;
- public InputReader(InputStream stream) {
- reader = new BufferedReader(new InputStreamReader(stream), 32768);
- tokenizer = null;
- }
- String next() {
- while (tokenizer == null || !tokenizer.hasMoreTokens()) {
- try {
- tokenizer = new StringTokenizer(reader.readLine());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return tokenizer.nextToken();
- }
- public int nextInt() {
- return Integer.parseInt(next());
- }
- public long nextLong() {
- return Long.parseLong(next());
- }
- public double nextDouble() {
- return Double.parseDouble(next());
- }
- }
- static InputReader r = new InputReader(System.in);
- static PrintWriter pw = new PrintWriter(System.out);
- static TreeMap<Integer, Integer> prices = new TreeMap<Integer, Integer>();
- public static void main(String[] args) {
- int n = r.nextInt(); // # tickets
- int m = r.nextInt(); // # customers
- for(int i = 1; i <= n; i++){
- add(r.nextInt());
- }
- for(int i = 1; i <= m; i++){
- int c = r.nextInt();
- if(prices.lowerKey(c+1) != null){
- pw.println(prices.lowerKey(c+1));
- remove(prices.lowerKey(c+1));
- } else {
- pw.println(-1);
- }
- }
- pw.close();
- }
- static void add(int val){
- if(prices.containsKey(val)){
- prices.put(val, prices.get(val) + 1);
- } else {
- prices.put(val, 1);
- }
- }
- static void remove(int val){
- prices.put(val, prices.get(val) - 1);
- if(prices.get(val).equals(0)){
- prices.remove(val);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement