Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define rep(i,a,b) for(ll i = (a); i < (b); ++i)
- #define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
- #define pb push_back
- #define fs first
- #define sc second
- typedef pair<ll,ll> ii;
- typedef vector<ll> vi;
- typedef vector<ii> vii;
- const int INF = ~(1<<31);
- const double pi = acos(-1);
- const double EPS = 1e-9;
- int n,k;
- struct cmp{
- bool operator()(const queue<int> &a, const queue<int> &b){
- return a.size() > b.size();
- }
- };
- int main(){
- cin.sync_with_stdio(false);
- priority_queue<queue<int>, vector<queue<int> >, cmp> pq;
- cin >> n >> k;
- rep(i,0,n){
- int a;
- cin >> a;
- int cnt = 0;
- while(true){
- if(cnt >= 2*pq.size()){
- queue<int> s;
- s.push(a+1000);
- pq.push(s);
- break;
- }else{
- queue<int> cur = pq.top();
- cnt++;
- pq.pop();
- if(cur.size() == k){
- while(!cur.empty()){
- if(cur.front() <= a){
- cur.pop();
- }else break;
- }
- pq.push(cur);
- }else{
- cur.push(a+1000);
- pq.push(cur);
- break;
- }
- }
- }
- }
- cout << pq.size() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment