P1631 序列合并https://www.luogu.com.cn/problem/P1631
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
#include <cstdlib>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 2000010;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
int n;
int a[MAXN];
int b[MAXN];
struct node {
int x, y, z;
node() {
}
node(int x1, int y1, int z1): x(x1), y(y1), z(z1) {
}
bool operator < (const node &b)const {
return x > b.x;
}
};
int main() {
priority_queue<node, vector<node> > que;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
for (int i = 1; i <= n; i++) {
scanf("%d", b + i);
}
for (int i = 1; i <= n; i++) {
que.push(node(a[i] + b[1], i, 1));
}
node t;
for (int i = 1; i <= n; i++) {
printf("%d ", que.top().x);
t = que.top();
que.pop();
que.push(node(a[t.y] + b[t.z + 1], t.y, t.z + 1));
}
return 0;
}