# 3110 binary heap exercises

Source: Internet
Author: User

3110 binary heap exercises
3110 binary heap Exercise 3

Time Limit: 3 s space limit: 128000 KB title level: Gold Title Description Description

Given N (N ≤ 500,000) and N integers (more ordered), sort them and output them.

Input description Input Description

N and N Integers

Output description Output Description

N integers (ascending)

Sample Input Sample Input

5

12 11 10 8 9

Sample output Sample Output

8 9 10 11 12

Data range and prompt Data Size & Hint

For 33% of data, N ≤ 10000

For the other 33% of data, N ≤ 100,000 0 ≤ each number ≤ 1000

For 100% of data, N ≤ 500,000 0 ≤ each number ≤ 2*10 ^ 9

` 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 long long int a[1000001]; 5 int main() 6 { 7     int n; 8     cin>>n; 9     for(int i=1;i<=n;i++)10     {11         cin>>a[i];12         push_heap(a+1,a+i+1,greater<int>());13     }14     int m=n;15     for(int i=1;i<=n;i++)16     {17         int d=a[1];18         cout<<d<<" ";19         pop_heap(a+1,a+m+1,greater<int>());20         m--;21     }22     return 0;23  } `

Related Keywords:
Related Article

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.