結果
問題 |
No.3298 K-th Slime
|
ユーザー |
|
提出日時 | 2025-10-05 14:04:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 161 ms / 2,000 ms |
コード長 | 945 bytes |
コンパイル時間 | 2,023 ms |
コンパイル使用メモリ | 205,228 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-10-05 14:04:40 |
合計ジャッジ時間 | 4,573 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int n,k,q; cin>>n>>k>>q; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; priority_queue<long long> PQlow; priority_queue<long long,vector<long long>,greater<long long>> PQup; auto push=[&](long long x){ if(PQlow.top()<=x) PQup.push(x); else{ PQup.push(PQlow.top()); PQlow.pop(); PQlow.push(x); } }; auto popget=[&](){ long long ret=PQlow.top(); PQlow.pop(); PQlow.push(PQup.top()); PQup.pop(); return ret; }; sort(a,a+n); for(int i=0;i<n;i++){ if(i<k) PQlow.push(a[i]); else PQup.push(a[i]); } PQup.push(2e18); while(q--){ int op; cin>>op; if(op==1){ long long x; cin>>x; push(x); } if(op==2){ long long y; cin>>y; auto val=popget(); push(val+y); } if(op==3){ auto ans=popget(); cout<<ans<<endl; push(ans); } } }