Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <algorithm>
- #include <iostream>
- #include <functional>
- using namespace std;
- int p, n, x;
- priority_queue<int> down;
- priority_queue<int, vector<int>, greater<int> > up;
- vector<int> ans;
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- scanf("%d", &p);
- for (int tst = 1; tst <= p; tst++) {
- while (!down.empty())
- down.pop();
- while (!up.empty())
- up.pop();
- ans.clear();
- scanf("%*d%d", &n);
- for (int i = 0; i < n; i++) {
- scanf("%d", &x);
- if (down.empty() || x <= down.top())
- down.push(x);
- else
- up.push(x);
- if (up.size() > down.size()) {
- down.push(up.top());
- up.pop();
- }
- if (down.size() > up.size() + 1) {
- up.push(down.top());
- down.pop();
- }
- if (i % 2 == 0)
- ans.push_back(down.top());
- }
- printf("%d %d", tst, ans.size());
- for (int i = 0; i < ans.size(); i++)
- printf("%c%d", i % 10 ? ' ' : '\n', ans[i]);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement