Hdu1425 sort [STL heap sorting]

Source: Internet
Author: User

Sorttime limit: 6000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others) Total submission (s): 27781 accepted submission (s): 8404

Problem description gives you n integers. Output The first m in the ascending order.
 
There are two rows of test data in each input group. The first row has two numbers n, m (0 <n, m <1000000), and the second row contains n different numbers, and all are integers in the range.
 
Output outputs the first m of each group of test data in ascending order.
 
Sample Input
5 33 -35 92 213 -644
 
Sample output
213 92 3HintUse VC/VC ++ to submit hint
 

#include <stdio.h>#include <algorithm>#define maxn 1000002using namespace std;int arr[maxn];int main(){    int n, m, i;    while(scanf("%d%d", &n, &m) == 2){        for(i = 0; i < n; ++i)            scanf("%d", &arr[i]);        make_heap(arr, arr + n);        printf("%d", arr[0]);        for(i = 0; i < m - 1; ++i){            pop_heap(arr, arr + n - i);            printf(" %d", arr[0]);        }        printf("\n");            }    return 0;}


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.