P1631 序列合并

 1 #include
 2 #include
 3 #include
 4 using namespace std;
 5 
 6 int a[100010];
 7 int b[100010];
 8 int p[100010];
 9 
10 bool operator >(pair<int, int>a, pair<int, int>b)
11 {
12     return a.first > b.first;
13 }
14 
15 priority_queueint,int>, vectorint,int>>,greaterint,int>>>heap;
16 
17 int main()
18 {
19     int n;
20     cin >> n;
21     for (int i = 1; i <= n; i++)
22     {
23         p[i] = 2;
24         cin >> a[i];
25     }
26     for (int i = 1; i <= n; i++)
27     {
28         cin >> b[i];
29     }
30     for (int i = 1; i <= n; i++)
31     {
32         heap.push(pair<int, int>(a[1] + b[i], i));
33     }
34     for (int i = 1; i <= n; i++)
35     {
36         cout << heap.top().first << " ";
37         if (p[heap.top().second] <= n) heap.push(pair<int, int>(a[p[heap.top().second]++] + b[heap.top().second], heap.top().second));
38         heap.pop();
39     }
40 }
View Code

 

你可能感兴趣的:(P1631 序列合并)