poj1442
来源:互联网 发布:如何注册淘宝会员 编辑:程序博客网 时间:2024/05/19 04:02
//============================================================================// Name : 1442.cpp// Author : // Version :// Copyright : Your copyright notice// Description : Hello World in C++, Ansi-style//============================================================================#include <stdio.h>#include <queue>#define M 3000using namespace std;int main() {int m, n, v;scanf("%d %d", &m, &n);int data[m];for (int i = 0; i < m; i++)scanf("%d", &data[i]);priority_queue<int, vector<int>, greater<int> > qbig;priority_queue<int> qsmall;int l = 0;for (int i = 0; i < n; i++) {scanf("%d", &v);while (l < v) {qbig.push(data[l++]);}qsmall.push(qbig.top());qbig.pop();if (!qbig.empty() && !qsmall.empty()) {while (qbig.top()< qsmall.top()) {qsmall.push(qbig.top());qbig.push(qsmall.top());qsmall.pop();qbig.pop();}}int top = qsmall.top();printf("%d\n",top);}return 0;}