Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define rep(i,a,b) for(ll i = (a); i < (b); ++i)
  5. #define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
  6. #define pb push_back
  7. #define fs first
  8. #define sc second
  9. typedef pair<ll,ll> ii;
  10. typedef vector<ll> vi;
  11. typedef vector<ii> vii;
  12.  
  13. const int INF = ~(1<<31);
  14. const double pi = acos(-1);
  15. const double EPS = 1e-9;
  16.  
  17. int n,k;
  18. struct cmp{
  19. bool operator()(const queue<int> &a, const queue<int> &b){
  20. return a.size() > b.size();
  21. }
  22. };
  23.  
  24. int main(){
  25. cin.sync_with_stdio(false);
  26. priority_queue<queue<int>, vector<queue<int> >, cmp> pq;
  27. cin >> n >> k;
  28. rep(i,0,n){
  29. int a;
  30. cin >> a;
  31. int cnt = 0;
  32. while(true){
  33. if(cnt >= 2*pq.size()){
  34. queue<int> s;
  35. s.push(a+1000);
  36. pq.push(s);
  37. break;
  38. }else{
  39. queue<int> cur = pq.top();
  40. cnt++;
  41. pq.pop();
  42. if(cur.size() == k){
  43. while(!cur.empty()){
  44. if(cur.front() <= a){
  45. cur.pop();
  46. }else break;
  47. }
  48. pq.push(cur);
  49. }else{
  50. cur.push(a+1000);
  51. pq.push(cur);
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. cout << pq.size() << endl;
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement