Bank Robbery 2
InterviewTime limit1sMemory limit256 MB
Given banks at positions X_i that open at time T_i, find the maximum total money Siwoo can rob while moving only rightward from a chosen start.
- Level
Easy3 of 10
- Topics
- Hash map, Implementation
- Solved
- No attempts yet
Problem
Siwoo, a professional bank robber, wants to rob banks. Along the straight path he runs on, there are banks. The -th bank is at a distinct coordinate on the line, and its door opens only when the time is exactly , so he can enter only then. Robbing this bank yields won.
Siwoo starts at an arbitrary integer coordinate on the line and moves. While he moves, his coordinate must not decrease (he may stop as long as he wants). Time starts at , and whenever the coordinate increases by , the time increases by .
Whenever Siwoo meets a bank whose door is open, he must rob it and move on. He is very skilled, so robbing a bank never increases the time at all.
Print the maximum amount of money Siwoo can obtain when he starts at a suitable position.
Input
The first line contains . ()
From the second line onward, the next lines each contain integers in the order where and increase. ()
All are distinct.
Output
Print the maximum amount of money Siwoo can obtain.