Woburn Challenge 2015-16 Round 1 - Senior Division
Welcome to the first Woburn Challenge in over a decade! We hope you find these contests fun and challenging.
Let's start by getting to know Woburn a little more. The motto of Woburn Collegiate Institute is Studium Eruditionis Crescat, or Let the Zeal for Learning Flourish. Clearly, Woburn values academic excellency, so it's no surprise that students often receive a hefty workload. There are also many extracurricular opportunities available to students, including Woburn Music, drama, and of course, the Programming Enrichment Group. Members of PEG meet Wednesdays and Fridays after school to study advanced computer science concepts, and are often assigned a fair amount of programming homework. Not only has PEG made students superb at programming, they've made students love programming. In fact, PEG students are often so hooked onto their programming homework that they forget about actual homework and become swamped with upcoming deadlines!
Being the natural problem-solvers they are, PEG students have realized that programming is once again the solution. They've decided to write a program to help them handle the workload of Woburn's courses, and they've asked you for help! Specifically, there are homework assignments that they would like to feed to your program. Each assignment is labeled with a unique integer from to , and will be given to your program in order. Each assignment is due minutes from now. Any given assignment can only be worked on up until the time at which it's due. The assignments will be given to your program in strictly increasing order of due date (in other words, ).
Furthermore, each assignment takes minutes to fully complete. The amount of marks you get on an assignment is obviously proportional to the amount of time you spend working on it. Since spending all minutes is guaranteed to be your best work, if you spend minutes working on assignment , where (spending extra time on an assignment does no good), you'll have to incur penalty marks. You can only work on one homework assignment at a time, but you can switch from one assignment to another at any point in time. Time is tight, so you might not be able to fully complete every assignment. The goal of the program is to help the user allocate their precious time amongst the assignments. Your program must answer the question: what's the minimum total number of penalty marks that can be incurred across all of the assignments?
Input Specification
The first line of input will contain a single integer , representing
the number of assignments to follow.
lines will follow, with the -th of these lines containing two
space-separated integers and , respectively representing
the number of minutes from now at which assignment is due and the
number of minutes it takes to complete assignment .
Output Specification
Output a single integer representing the minimum total penalty marks that can be incurred across all of the assignments, if your program schedules the assignments optimally.
Sample Input
4
40 40
80 60
120 30
130 80
Sample Output
80
Explanation
There are four assignments, respectively due , , , and minutes from now and respectively requiring , , , and minutes to complete. One way to optimally tackle the assignments is as follows:
- Immediate start working on assignment . You'll be done just in the nick of time and incur no penalty marks.
- Right after you hand in assignment (at minutes in), start working on assignment . Unfortunately, you'll only have minutes to work on the assignment, and so you'll have to incur penalty marks.
- Right after you hand in assignment (at minutes in), start working on assignment . You'll be able to get minutes of work on it before the due date (at minutes in). You'll have to incur penalty marks.
- Unfortunately, there was no time at all to tackle assignment , so you'll have to accept a zero and incur the full penalty marks.
In total, there are penalty marks incurred. There may be other ways to tackle the assignments, but it turns out that they will all incur penalty marks or more.
Comments