2269:minval time limit: 3 Sec Memory limit:
Submissions: 638 Resolution: 65
Submitted State [Discussion Version] [Propositional person: external import] Title Description
There are two sequences A and b of length n, and the sum of each number in A and B can be obtained N2 and, the N2 and the smallest n.
Input
The first line enters a positive integer N (1<=n<=100000);
The second row n integer AI and ai<=109; the third row n integer bi and bi<=109.
Output
Output only one row, containing n integers, from small to large output this n smallest and, adjacent numbers separated by a space.
Sample input
51 3 2 4 56 3 4 1 7
Sample output
2 3 4) 4 5
/*Heap Sort (priority queue) * Maintain n minimum number * Don't forget to sort*/#include<queue>#include<iostream>#include<cstdio>#include<algorithm>using namespacestd;#defineMAXN 110000intN;intNUM1[MAXN], NUM2[MAXN]; Priority_queue<int>Min_num;intRESULT[MAXN];intMain () {CIN>>N; for(intI=1; I<=n; i++) {scanf ("%d", &Num1[i]); } for(intj=1; J<=n; J + +) {scanf ("%d", &Num2[j]); } sort (Num1+1, num1+n+1) ; Sort (num2+1, num2+1+N); for(intI=1; I<=n; i++) {Min_num.push (num1[1] +Num2[i]); } for(intI=2; I<=n; i++){ for(intj=1; J<=n; J + +){ if(Num1[i] + num2[j] <Min_num.top ()) {Min_num.pop (); Min_num.push (Num1[i]+Num2[j]); }Else { Break ; } } } for(intI=1; I<=n; i++) {Result[i]=Min_num.top (); Min_num.pop (); } for(intI=n; i>=1; i--) {printf ("%d", Result[i]); } return 0 ; }
2269:minval (priority queue heap sort)