結果
| 問題 |
No.649 ここでちょっとQK!
|
| ユーザー |
|
| 提出日時 | 2018-02-09 23:06:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 293 ms / 3,000 ms |
| コード長 | 1,216 bytes |
| コンパイル時間 | 1,105 ms |
| コンパイル使用メモリ | 76,920 KB |
| 実行使用メモリ | 5,916 KB |
| 最終ジャッジ日時 | 2024-10-08 18:06:21 |
| 合計ジャッジ時間 | 6,027 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int main(){
int Q, K;
cin >> Q >> K;
priority_queue<long, vector<long>, less<long>> K_left;
long Kth = -1;
priority_queue<long, vector<long>, greater<long>> K_right;
int array_size = 0;
for(int i = 0; i < Q; i++){
int type;
cin >> type;
if(type == 1){
long num;
cin >> num;
array_size++;
K_left.push(num);
if(array_size == K){
Kth = K_left.top();
K_left.pop();
}else if(array_size > K){
K_right.push(Kth);
K_right.push(K_left.top());
K_left.pop();
Kth = K_right.top();
K_right.pop();
}
}else{
if(array_size < K){
cout << -1 << endl;
}else{
array_size--;
cout << Kth << endl;
if(array_size >= K){
Kth = K_right.top();
K_right.pop();
}else{
Kth = -1;
}
}
}
}
}