BWPOINTS - VOI 2011 Nối điểm đen trắng

Tác giả: skyvn97

Ngôn ngữ: C++

#include<stdio.h>
#include<queue>
using namespace std;
int n;
int c,k;
typedef priority_queue<int,vector<int>,greater<int> > pq;
pq b,w;
void process(void) {
    int i,x;
    scanf("%d",&n);
    for (i=1;i<=n;i=i+1) {
        scanf("%d",&x);
        b.push(x);
    }
    for (i=1;i<=n;i=i+1) {
        scanf("%d",&x);
        w.push(x);
    }
    c=-1e9-1;
    k=0;
    while ((!b.empty()) && (!w.empty())) {
        k=k+1;
        c=max(b.top(),w.top());
        while ((!b.empty()) && (b.top()<=c)) b.pop();
        while ((!w.empty()) && (w.top()<=c)) w.pop();
    }
    printf("%d",k);
}
int main(void) {
    process();
}

Download