编程介的小学生 2017-11-02 12:52 采纳率: 20.3%
浏览 855
已采纳

Bus Fair

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 for you two).

Now as a programmer, you want to show your creativity in buying 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 2coin 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 2km! And you can safely reach to your destination, 2km 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 should manage all to reach their destination spending the minimum amount of coins. Then tell us how much we should 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 to. You can assume that the distance a man wants to go is always less than 10000.

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

Sample Input
2
1
2
2
2
3

Sample Output
2
4

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-11-26 14:09
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输