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;}