首页 > 其他 > 详细

P1631 序列合并

时间:2019-10-09 15:21:22      阅读:102      评论:0      收藏:0      [点我收藏+]
技术分享图片
 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 序列合并

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!