标签: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 }
标签:gre bsp iostream stream 合并 span ide heap i++
原文地址:https://www.cnblogs.com/thjkhdf12/p/11641372.html