Stop Overtime!
InterviewTime limit1sMemory limit1024 MB
Given N tasks with deadlines and required workdays, find the fewest overtime days needed to finish every task on time, or -1 if that is impossible.
- Level
Medium5 of 10
- Topics
- Greedy, Binary search, Sorting
- Solved
- No attempts yet
Problem
The development project consists of tasks. Each task requires workdays and must be finished before days pass after the project starts. Regular work alone looks unable to finish every task on time, so Joonmin gives up his personal rest time and works overtime.
The project starts on a Monday. Regular work runs only from Monday to Friday. Overtime can be worked at most once per day regardless of weekday, and one overtime session finishes one day of work.
Input
The first line contains the number of tasks .
From the second line to the th line, each line contains the deadline and the time required for a task, separated by a space.
Output
Print the minimum number of overtime days needed to finish all tasks before their deadlines.
If there is no way to finish all tasks before their deadlines, print .