2014
03-23

# Bus Fair

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.

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.

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.

2
1
2
2
2
3

2
4

#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a, const void *b){
return *(int *)a - *(int *)b;
}
int main() {
int x[1001], n, i, j, tickets;
while(scanf("%d", &n) != EOF){
for(i = 0; i < n; i++)
scanf("%d", x + i);
qsort(x, n, sizeof(x[0]), cmp);
tickets = 0;
for(i = 0; i < n; i++)
if(x[i] * (n - i) > tickets)
tickets = x[i] * (n - i);
printf("%d\n", tickets);
}
}

1. 真正的司机，这种速度的应急状况都处理不了的话，不如不开车。 连刚考驾照出来的新手们都知道会减速 实在不行直接停车。图中这位司机看样子 压根视线没在路上。那天看到一公交车司机紧急避让一辆在特么在实线掉头的二逼车，差点闹到全公交车的人下去打他了。全靠公交车

2. 真正的司机，这种速度的应急状况都处理不了的话，不如不开车。 连刚考驾照出来的新手们都知道会减速 实在不行直接停车。图中这位司机看样子 压根视线没在路上。那天看到一公交车司机紧急避让一辆在特么在实线掉头的二逼车，差点闹到全公交车的人下去打他了。全靠公交车

3. 真正的司机，这种速度的应急状况都处理不了的话，不如不开车。 连刚考驾照出来的新手们都知道会减速 实在不行直接停车。图中这位司机看样子 压根视线没在路上。那天看到一公交车司机紧急避让一辆在特么在实线掉头的二逼车，差点闹到全公交车的人下去打他了。全靠公交车

4. 真正的司机，这种速度的应急状况都处理不了的话，不如不开车。 连刚考驾照出来的新手们都知道会减速 实在不行直接停车。图中这位司机看样子 压根视线没在路上。那天看到一公交车司机紧急避让一辆在特么在实线掉头的二逼车，差点闹到全公交车的人下去打他了。全靠公交车

5. 真正的司机，这种速度的应急状况都处理不了的话，不如不开车。 连刚考驾照出来的新手们都知道会减速 实在不行直接停车。图中这位司机看样子 压根视线没在路上。那天看到一公交车司机紧急避让一辆在特么在实线掉头的二逼车，差点闹到全公交车的人下去打他了。全靠公交车

6. 真正的司机，这种速度的应急状况都处理不了的话，不如不开车。 连刚考驾照出来的新手们都知道会减速 实在不行直接停车。图中这位司机看样子 压根视线没在路上。那天看到一公交车司机紧急避让一辆在特么在实线掉头的二逼车，差点闹到全公交车的人下去打他了。全靠公交车

7. 真正的司机，这种速度的应急状况都处理不了的话，不如不开车。 连刚考驾照出来的新手们都知道会减速 实在不行直接停车。图中这位司机看样子 压根视线没在路上。那天看到一公交车司机紧急避让一辆在特么在实线掉头的二逼车，差点闹到全公交车的人下去打他了。全靠公交车

8. 真正的司机，这种速度的应急状况都处理不了的话，不如不开车。 连刚考驾照出来的新手们都知道会减速 实在不行直接停车。图中这位司机看样子 压根视线没在路上。那天看到一公交车司机紧急避让一辆在特么在实线掉头的二逼车，差点闹到全公交车的人下去打他了。全靠公交车

9. 真正的司机，这种速度的应急状况都处理不了的话，不如不开车。 连刚考驾照出来的新手们都知道会减速 实在不行直接停车。图中这位司机看样子 压根视线没在路上。那天看到一公交车司机紧急避让一辆在特么在实线掉头的二逼车，差点闹到全公交车的人下去打他了。全靠公交车

10. 题本身没错，但是HDOJ放题目的时候，前面有个题目解释了什么是XXX定律。
这里直接放了这个题目，肯定没几个人明白是干啥