HDU 3420 -- bus fair ACM

Source: Internet
Author: User
Bus fair

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/others) total submission (s): 600 accepted submission (s): 293

 

Problem description

 

You are now in foolish land. once moving in foolish land you found that there is a strange bus fair system. the Fair of moving one kilometer by bus in that country is one coin. if you want to go to X km and your friend wants to go to y km then you can buy a ticket of x + y coins (You are also allowed to buy two or more tickets you two ). now as a programmer, you want to show your creativity in buy Ing tickets! Suppose, your friend wants to go 1 km and you want to go 2 km. Then it's enough for you to buy a 2 coin ticket! Because both of you are valid passengers before crossing the first km. and when your bus cross the first km your friend gets down from the bus. So you have the ticket of 2 km! And you can safely reach to your destination, 2 km using that ticket. now, you have a large group of friends and they want to reach to different distance. you think that you are smart enough that you can buy tickets that shocould manage all to reach their destination spending the minimum amount of coins. then tell us how much we shoshould at least pay to reach our destination.

 

Input

 

There are multiple test cases. each case start with a integer N, the total number of people in that group. 0 <= n <= 1000. then comes n integers, each of them stands for a distance one of the men of the Group wants to go. you can assume that the distance a man wants to go is always less than 10000.

 

Output

 

Your program shocould print a single integer for a single case, the minimum amount of coins the group shoshould spend to reach to the destination of all the members of that group.

 

Sample Input

 

212223

 

Sample output

 

24

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3420
 1 #include<stdio.h> 2 #include<stdlib.h> 3 int cmp(const void* a,const void* b) 4 { 5     return *(int *)a - *(int *)b; 6 } 7 int main() 8 { 9     int n,tmp,sum,i;10     int num[10000];11     while(~scanf("%d",&n))12     {13         for(i=0;i<n;i++)14             scanf("%d",&num[i]);15         sum=0;16         qsort(num,n,sizeof(num[0]),cmp);17         for(i=0;i<n;i++)18         {19             tmp=num[i]*(n-i);20             if(tmp>sum)21                 sum=tmp;22         }23         printf("%d\n",sum);24     }25     return 0;26 }


 

 

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.