码迷,mamicode.com
首页 > 其他好文 > 详细

P1631 序列合并

时间:2019-10-09 14:04:52      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:gre   bsp   iostream   stream   合并   span   ide   heap   i++   

技术图片
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<queue>
 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_queue<pair<int,int>, vector<pair<int,int>>,greater<pair<int,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 序列合并

标签:gre   bsp   iostream   stream   合并   span   ide   heap   i++   

原文地址:https://www.cnblogs.com/thjkhdf12/p/11641372.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!