Minval_ Priority Queue Sequencing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.