HDU-3420 bus fair.

Source: Internet
Author: User

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 }

  

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.