HDU 3785 find monopoly (SORT)

Source: Internet
Author: User

HDU 3785 find monopoly (SORT)

Find Monopoly Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 4132 Accepted Submission (s): 1698


Problem Description There are n people in Wuzhen, Tongxiang, Zhejiang province. Please find the first m monopoly in this town.
The Input contains multiple groups of test cases.
Each use case first contains two integers n (0 If n and m are both 0, the input ends.
Output please Output the number of properties of the first m richest people in Wuzhen, and the number of items in front of the multiple items. If there are less than m items, all items are Output, and each group occupies one row.
Sample Input
3 12 5 -15 31 2 3 4 50 0

Sample Output
55 4 3
# Include
  
   
# Include
   
    
# Include
    
     
Using namespace std; int a [100010]; int aux [100010]; void swap (int * a, int * B) {int t = * a; * a = * B; * B = t;} int partition (int a [], int l, int h) {int I = l; int j = h + 1; int v = a [l]; while (1) {while (a [++ I]> v) if (I = h) break; while (a [-- j]
     
      
= J) break; swap (& a [I], & a [j]);} swap (& a [l], & a [j]); return j ;} void q_sort (int a [], int l, int h) {if (l> = h) return; int j = partition (a, l, h); q_sort (, l, J-1); q_sort (a, j + 1, h);} void merge (int a [], int l, int mid, int h) {int I = l; int j = mid + 1; for (int k = l; k <= h; ++ k) aux [k] = a [k]; for (int k = l; k <= h; ++ k) {if (I> mid) a [k] = aux [j ++]; else if (j> h) a [k] = aux [I ++]; else if (aux [I]> aux [j]) a [k] = aux [I ++]; else a [k] = aux [j ++] ;}} void m_sort (int a [], int l, int h) {if (h <= l) return; int mid = l + (h-l)/2; m_sort (a, l, mid); m_sort (a, mid + 1, h); merge (a, l, mid, h);} int main (int argc, char * argv []) {freopen ("random 5.in"," r ", stdin); int n, m; while (scanf ("% d", & n, & m) = 2) {memset (a, 0, sizeof ()); if (n = 0 & m = 0) return 0; for (int I = 0; I
      
       
Merged and quickly written each time ~


Related Article

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.