Interview Room of Terror
InterviewTime limit1sMemory limit1024 MB
Interviews run one at a time. Find the minimum sum of the finish times of all departments, given each department's total interview time.
Problem
Employees of the Korea Information Technology Promotion Agency each have a one-on-one interview with the president once every six months.
The agency has departments. A department can leave work only after every employee in it has finished their interview. Interviews are held one at a time.
Find the minimum possible value of the sum of the times at which all departments leave work.
Input
The first line contains the number of departments (). The next lines each contain the number of employees in a department and the interview time per employee, separated by spaces. The total number of employees across all departments is at most , and the interview time per employee is an integer from to minutes.
Output
Print the minimum possible sum of the times at which all departments leave work, in minutes.