Advertisement
Guest User

Untitled

a guest
Sep 8th, 2013
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <stack>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <string>
  10. #include <algorithm>
  11. #include <iostream>
  12. #include <functional>
  13. using namespace std;
  14.  
  15. int p, n, x;
  16. priority_queue<int> down;
  17. priority_queue<int, vector<int>, greater<int> > up;
  18. vector<int> ans;
  19.  
  20. int main() {
  21.     //freopen("input.txt", "r", stdin);
  22.     //freopen("output.txt", "w", stdout);
  23.  
  24.     scanf("%d", &p);
  25.     for (int tst = 1; tst <= p; tst++) {
  26.         while (!down.empty())
  27.             down.pop();
  28.         while (!up.empty())
  29.             up.pop();
  30.         ans.clear();
  31.         scanf("%*d%d", &n);
  32.         for (int i = 0; i < n; i++) {
  33.             scanf("%d", &x);
  34.             if (down.empty() || x <= down.top())
  35.                 down.push(x);
  36.             else
  37.                 up.push(x);
  38.             if (up.size() > down.size()) {
  39.                 down.push(up.top());
  40.                 up.pop();
  41.             }
  42.             if (down.size() > up.size() + 1) {
  43.                 up.push(down.top());
  44.                 down.pop();
  45.             }
  46.             if (i % 2 == 0)
  47.                 ans.push_back(down.top());
  48.         }
  49.         printf("%d %d", tst, ans.size());
  50.         for (int i = 0; i < ans.size(); i++)
  51.             printf("%c%d", i % 10 ? ' ' : '\n', ans[i]);
  52.         printf("\n");
  53.     }
  54.    
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement