GPA
Time limit1sMemory limit256 MB
Given n courses with original grade A_i and altered grade B_i, pick a subset to change so the number of days where the new grade falls below the running average of earlier grades is minimized.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
This semester, Alice took courses. She has now finished all her final exams, and over the next days she will receive her grades.
On the -th day, Alice learns her grade in the -th course. If is strictly less than the average grade of the first courses, Alice is sad that day.
Bob has broken into the university's database. He can choose a set of courses ( may be empty). Then, for each course in , he can change Alice's grade from to .
Bob wants to minimize the number of days Alice is sad. Help him decide which courses' grades he should change.
Alice is always happy on the first day.
Input
The first line contains a single integer ().
The next lines follow. The -th of these lines contains two integers and ().
Output
Output the minimum number of days Alice is sad.