# UVA online judge Solution 501 – Black Box – Solution of UVA problem

### UVA Online Judge Solution 501 – Black Box | Volume 5

Problem Name: 501 – Black Box
Problem Number : UVA – 501 – Black Box
Online Judge : UVA Online Judge Solution
Volume: 5
Solution Language : C plus plus

### UVA Solution 501 Code in CPP:

`#include <cstdio>#include <queue>#include <vector>using namespace std;int main() {    int t, n, m, x;    scanf("%d", &t);    while(t--) {        scanf("%d %d", &n, &m);        queue<int> ADD, GET;        for(int i = 0; i < n; i++) {            scanf("%d", &x);            ADD.push(x);        }        for(int i = 0; i < m; i++) {            scanf("%d", &x);            GET.push(x);        }        priority_queue<int, vector<int>, greater<int> > MinHeap;        priority_queue<int, vector<int>, less<int> > MaxHeap;        int i = 0;        while(!ADD.empty()) {            if( !MinHeap.empty() && ADD.front() > MaxHeap.top())                MinHeap.push(ADD.front());            else                MaxHeap.push(ADD.front());            ADD.pop();            while(!GET.empty() && MaxHeap.size()+MinHeap.size() == GET.front()) {                while(MaxHeap.size() != i) {                    if(MaxHeap.size() < i) {                        MaxHeap.push(MinHeap.top());                        MinHeap.pop();                    } else if(MaxHeap.size() > i) {                        MinHeap.push(MaxHeap.top());                        MaxHeap.pop();                    }                }                printf("%dn", MinHeap.top());                i++, GET.pop();            }        }        if(t)            puts("");    }    return 0;}`
Tags:
UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA online judge Solution 501 – Black Box – Solution of UVA problem, UVA 501 in C++, UVA 501 problem solution
UVA online Judge Solution – UVA 110 solution in C, C++. UVA Meta loopless sort online Judge Solution
Solve the UVA problem 110 now and be a little master at UVA online Judge..
Happy Coding..
Any problem comment here or comment in the above site’s comment  box.

#### By Maniruzzaman Akash

Maniruzzaman Akash is a freelance web developer with most popular Laravel PHP frameork and Vue JS