結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
packer_jp
|
| 提出日時 | 2018-02-09 23:20:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 270 ms / 3,000 ms |
| コード長 | 1,191 bytes |
| コンパイル時間 | 3,231 ms |
| コンパイル使用メモリ | 164,448 KB |
| 実行使用メモリ | 5,912 KB |
| 最終ジャッジ日時 | 2024-10-09 02:06:20 |
| 合計ジャッジ時間 | 8,138 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int Q, K;
priority_queue<int> pq1;
priority_queue<int, vector<int>, greater<int> > pq2;
vector<int> ans;
signed main() {
cin >> Q >> K;
for (int i = 0; i < Q; i++) {
int kind;
cin >> kind;
if (kind == 1) {
int v;
cin >> v;
if (pq1.size() < K) {
pq1.push(v);
} else if (v < pq1.top()) {
pq2.push(pq1.top());
pq1.pop();
pq1.push(v);
} else {
pq2.push(v);
}
} else {
if (pq1.size() < K) {
ans.push_back(-1);
} else if (pq2.empty()) {
ans.push_back(pq1.top());
pq1.pop();
} else {
ans.push_back(pq1.top());
pq1.pop();
pq1.push(pq2.top());
pq2.pop();
}
}
}
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
return 0;
}
packer_jp