Archive / 2021 / Final Round — Day 2
Best King
King Unumagudut decided to travel each city one after another from the southernmost city to the northernmost city, along the way in the newly built motorway. There are N cities and cities are numbered from 0 to N-1 from the southernmost city to the northernmost city. Location of city i is (0, yi ). No two cities are located at the same position.
The king wants to hold meetings in some of the cities they stop by. As the king’s chief advisor you want the king to keep believing that he’s the most successful ruler in the world. Therefore you want to hold the meetings in some of the cities during the king’s travel so that total success score is maximized.
For each city i, you know how much positive score you can achieve (Pi ) because you can control the crowd taking part in the meetings. But for each city i they hold a meeting, the king will lose score equal to Li * distance to any previous city they held a meeting at.
They will not lose score for the first meeting they hold.
Given Pi, Li and yi for all N cities, calculate the maximum score
Input Format
First line contains an integer, N.
Next N lines represent data for city 0 to N-1 in that order. Each line will contain 3 integers separately representing yi, Pi and Li respectively.
Output Format
Output only one integer, the maximum score.
Constraints
- 0 \(\leq\) Li, Pi \(\leq\) 103
- 0 \(\leq\) yi \(\leq\) 2*106
- 0 \(\leq\) N \(\leq\) 106
Limits
- Time Limit: 2s
- Memory Limit: 256MB
Sample Input 0
3
0 10 0
1 1 12
3 7 2
Sample Output 0
11
Open on HackerRank ↗ · Markdown source · Back to the archive