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
CATEGORY tag
Tags click here to expand
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 }