結果

問題 No.649 ここでちょっとQK!
ユーザー uafr_csuafr_cs
提出日時 2018-02-09 22:43:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 965 ms / 3,000 ms
コード長 2,706 bytes
コンパイル時間 2,620 ms
コンパイル使用メモリ 86,516 KB
実行使用メモリ 59,680 KB
最終ジャッジ日時 2024-04-17 05:18:20
合計ジャッジ時間 17,110 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
37,300 KB
testcase_01 AC 57 ms
36,784 KB
testcase_02 AC 56 ms
36,716 KB
testcase_03 AC 965 ms
51,556 KB
testcase_04 AC 596 ms
52,956 KB
testcase_05 AC 508 ms
52,872 KB
testcase_06 AC 433 ms
52,392 KB
testcase_07 AC 54 ms
36,924 KB
testcase_08 AC 56 ms
37,224 KB
testcase_09 AC 56 ms
37,140 KB
testcase_10 AC 54 ms
37,004 KB
testcase_11 AC 54 ms
36,924 KB
testcase_12 AC 441 ms
48,908 KB
testcase_13 AC 441 ms
49,032 KB
testcase_14 AC 447 ms
49,152 KB
testcase_15 AC 477 ms
48,860 KB
testcase_16 AC 441 ms
48,128 KB
testcase_17 AC 499 ms
47,912 KB
testcase_18 AC 526 ms
48,492 KB
testcase_19 AC 556 ms
48,276 KB
testcase_20 AC 574 ms
48,852 KB
testcase_21 AC 579 ms
49,636 KB
testcase_22 AC 600 ms
51,012 KB
testcase_23 AC 630 ms
55,060 KB
testcase_24 AC 639 ms
55,524 KB
testcase_25 AC 659 ms
56,216 KB
testcase_26 AC 753 ms
59,680 KB
testcase_27 AC 99 ms
38,144 KB
testcase_28 AC 100 ms
38,292 KB
testcase_29 AC 100 ms
38,324 KB
testcase_30 AC 402 ms
48,360 KB
testcase_31 AC 438 ms
47,804 KB
testcase_32 AC 53 ms
37,164 KB
testcase_33 AC 53 ms
37,296 KB
testcase_34 AC 54 ms
37,076 KB
testcase_35 AC 54 ms
37,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
 
public class Main {
	
	
	public static void main(String[] args) throws IOException {
		try (Scanner sc = new Scanner(System.in)) {
			final long Q = sc.nextLong();
			final long K = sc.nextLong();
			
			PriorityQueue<Long> main_queue = new PriorityQueue<Long>(Collections.reverseOrder());
			PriorityQueue<Long> other_queue = new PriorityQueue<Long>();
			
			for(int i = 0; i < Q; i++){
				final int q = sc.nextInt();
				
				if(q == 1){
					final long v = sc.nextLong();
					//System.out.println(v + " " + main_queue + " " + other_queue);
					
					main_queue.add(v);
					while(main_queue.size() > K){
						other_queue.add(main_queue.poll());
					}
				}else{
					if(main_queue.size() < K){
						System.out.println(-1);
					}else{
						final long v = main_queue.poll();
						System.out.println(v);
						if(!other_queue.isEmpty()){ main_queue.add(other_queue.poll()); }
					}
				}
			}
		}
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}
0