If You Sleep Now, You Dream
InterviewTime limit2sMemory limit1024 MB
Given N task deadlines, choose a sleep reduction X so that each task takes A-X time after sleeping BX, and find the most tasks that can finish by their deadlines.
- Level
Easy3 of 10
- Topics
- Sorting, Greedy, Brute force
- Solved
- No attempts yet
Problem
"If you sleep now, you dream, but if you study now, you achieve your dream." People say this, but Silver thinks differently. Silver believes that sleeping well raises study efficiency, and that matters most. Silver has many assignments and plans to finish as many as possible by sleeping a moderate amount.
Silver has tasks, and the deadline of the -th task is . Silver starts at time 0 and can choose any task to work on at any moment. Only one task can be in progress at a time, and Silver cannot start another task before finishing the current one. Finishing one task takes units of time.
Silver chooses an integer with , then can sleep for units of time. After sleeping, finishing one task takes units of time. Silver can sleep at most once, and cannot sleep while a task is in progress. Silver can also sleep starting at time 0.
Silver wants to maximize the number of tasks finished by their deadlines. A task finished exactly at time counts as finished on time. Find the maximum number of tasks that can be finished by their deadlines.
Input
The first line contains the number of tasks , the initial time needed to finish one task, and the integer that sets the reduction rate, separated by spaces. ()
The second line contains integers giving the deadline of each task, separated by spaces. ()
All numbers in the input are integers.
Output
The first line prints the maximum number of tasks that can be finished by their deadlines.