Subin and the Melting Candy
InterviewTime limit1sMemory limit64 MB
Starting at the origin and moving only right or up, visit baskets over time to maximize total candies collected, where a basket's candies shrink by one per time unit.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
Subin is sitting on the coordinate plane. "I love the coordinate plane so much!!" said Subin. The plane has candy baskets, and each basket holds candies. The baskets are at , and Subin starts at .
The weather is hot today. Each time unit of time passes, one candy melts away from every basket that still has candy left. After units of time have passed, a basket holds candies.
Subin is very hungry, so when he reaches a basket he eats all the candies in it instantly. Eating takes no time. When Subin moves a distance of , unit of time passes. Subin can move only up (the direction in which the coordinate increases) or right (the direction in which the coordinate increases).
Write a program that finds the maximum number of candies Subin can eat.
Input
The first line contains and .
Each of the next lines contains the position , of one candy basket. (, , )
No two candy baskets share a position, and there is no candy basket at .
Output
Print the maximum number of candies Subin can eat.