2269: Time limit: 3 Sec Memory limit:
Submissions: 839 resolution: 151
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
Source
Zhengzhou Institute of Light Industry Tenth annual ACM Program Design Contest
#include <iostream>#include<algorithm>#include<queue>#include<vector>using namespacestd; priority_queue<int> Q;//Big first-out teampriority_queue<int, vector<int, greater<int>> Q2;//Small First Out team#defineMAXN 100000intN, M;intNUM1[MAXN], NUM2[MAXN];intMain () { while(Cin >>N) { for(inti =0; I < n; i++) {cin>>Num1[i]; } for(inti =0; I < n; i++) {cin>>Num2[i]; } sort (NUM1, Num1+N); Sort (num2, num2+N); for(inti =0; I < n; i++) { //Initialize add n elementsQ.push (Num1[i] + num2[0]); } inttemp; intQ; for(inti =0; I < n; i++){ for(intj =1; J < N; J + +) {//cannot repeat elements that were previously addedtemp = Num1[i] +Num2[j]; Q=Q.top (); Q.pop (); if(Q <=temp) {Q.push (Q); Break; } Else{Q.push (temp); } } } for(inti =0; I < n; i++) {Q=Q.top (); Q.pop (); Num1[i]=Q; } for(inti = n-1; I >=0; i--) {cout<<Num1[i]; if(I! =0) {cout<<" "; }} cout<<Endl; } return 0; }
Minval_ Priority Queue Sequencing