In the evening, it was a bit cool. This is a transportation system where tickets can be shared. That is to say, when everyone is on a bus, it is enough to meet the requirements of all people to add up less time than the total face value of the ticket, so when a person wants to sit farther down, he only needs to check whether the purchased ticket is sufficient. If not, he needs to buy a new ticket. That is to say, the ticket can meet the requirements of the people behind the ticket to arrive at the station. Therefore, the rule for each update is whether the total number of tickets in front of the ticket can reach the next stop. If yes, the cost remains the same. Otherwise, the cost is described above.
The Code is as follows:
1 #include <cstdio>
2 #include <cstring>
3 #include <cstdlib>
4 #include <algorithm>
5 #define Max( a, b ) (a) > (b) ? (a) : (b);
6 using namespace std;
7
8 int rec[1005];
9
10 int main()
11 {
12 int N;
13 while( scanf( "%d", &N ) != EOF )
14 {
15 int cost = 0;
16 for( int i = 0; i < N; ++i )
17 {
18 scanf( "%d", &rec[i] );
19 }
20 sort( rec, rec + N );
21 for( int i = 0; i < N; ++i )
22 {
23 if( cost < ( N - i ) * rec[i] )
24 cost = ( N - i ) * rec[i];
25 }
26 printf( "%d\n", cost );
27 }
28 return 0;
29 }