結果
問題 |
No.649 ここでちょっとQK!
|
ユーザー |
![]() |
提出日時 | 2019-11-28 01:57:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 3,000 ms |
コード長 | 1,172 bytes |
コンパイル時間 | 1,814 ms |
コンパイル使用メモリ | 172,600 KB |
実行使用メモリ | 6,068 KB |
最終ジャッジ日時 | 2024-11-15 22:08:05 |
合計ジャッジ時間 | 4,269 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll q,k; cin>>q>>k; ll ans=-1; priority_queue<ll,vector<ll>> que; priority_queue<ll,vector<ll>,greater<ll>> gre; while(q--){ ll t; cin>>t; if(t==1){ ll v; cin>>v; if(que.size()==k){ if(ans < v) gre.push(v); else { que.push(v); gre.push(que.top()); que.pop(); ans = que.top(); } } else{ que.push(v); if(que.size()==k){ ans = que.top(); } } } if(t==2){ cout << ans << "\n"; if(que.size()==k){ que.pop(); ans = -1; if(gre.size()){ ans = gre.top(); que.push(ans); gre.pop(); } } } } }