#P7667. [JOI 2018 Final] 美术展览 / Art Exhibition
[JOI 2018 Final] 美术展览 / Art Exhibition
Description
There are artworks that are candidates for the exhibition. The artworks are numbered from to . Each artwork is defined by two integers: size and value. Artwork () has size , and artwork has value .
In the exhibition, at least one artwork will be selected and displayed. Since the exhibition hall is large enough, it is possible to display all artworks. However, due to the aesthetic sense of the people of the JOI Republic, we want the selected artworks to have sizes that do not differ too much. On the other hand, we also want to display many high-value artworks. We decide to select the artworks for the exhibition according to the following rules:
- Among the selected artworks, let be the maximum size, and let be the minimum size. Let be the total value of the selected artworks.
- Then, we want to maximize .
Given the number of candidate artworks for the exhibition, and the size and value of each artwork, write a program to compute the maximum value of .
Input Format
The first line contains an integer , the number of candidate artworks for the exhibition. Each of the next lines, the -th line contains two space-separated integers and , meaning that artwork has size and value .
Output Format
The only line contains one integer, the maximum value of .
3
2 3
11 2
4 5
6
6
4 1
1 5
10 3
9 1
4 2
5 3
7
15
1543361732 260774320
2089759661 257198921
1555665663 389548466
4133306295 296394520
2596448427 301103944
1701413087 274491541
2347488426 912791996
2133012079 444074242
2659886224 656957044
1345396764 259870638
2671164286 233246973
2791812672 585862344
2996614635 91065315
971304780 488995617
1523452673 988137562
4232545716
Hint
Constraints
For of the testdata, , (), ().
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): No additional constraints.
Sample Explanation
For Sample : There are candidate artworks in this exhibition. The size and value of each artwork are as follows:
- Artwork has size and value .
- Artwork has size and value .
- Artwork has size and value .
In this case, if we choose artwork and artwork for the exhibition, we have as follows:
- Among the selected artworks, artwork has the largest size. Therefore, .
- Among the selected artworks, artwork has the smallest size. Therefore, .
- The total value of the selected artworks is . Therefore, .
Since cannot be greater than , output .
Problem Notes
This problem is from T2: Art Exhibition of The 17th Japanese Olympiad in Informatics (JOI 2017/2018) Final Round.
Translated and organized by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号