Team Programming Contest
Time limit1sMemory limit128 MB
Each member-computer can solve a sequence of problems they are able to solve, each taking r minutes; maximize the number solved within t minutes and minimize total penalty.
- Level
Medium7 of 10
- Topics
- Greedy, Sorting, Implementation, Binary search
- Solved
- No attempts yet
Problem
Bartie and his teammates take part in a team programming contest. Each team has members and is given computers. The contest lasts minutes, during which the members try to solve programming problems.
Penalties are added up as follows: finishing a problem minutes after the start of the contest costs penalty points. A team that solves more problems always ranks higher; among teams that solve the same number of problems, the one with the smaller total penalty ranks higher.
Before the contest Bartie reads all of the statements and knows his team so well that he can tell exactly which member is able to solve which problem. Any member who is able to solve a problem needs exactly minutes of computer time to finish it. Each member has one computer and can work on at most one problem at a time, so a member who takes on several problems solves them one after another, back to back.
Given, as known at the start of the contest, which member is able to solve which problem, find the best result the team can reach: the greatest number of problems it can solve and, for that number of problems, the smallest possible total penalty.
Input
The first line contains five integers , , , , and (, ), separated by single spaces: the number of members on the team, the number of problems, the time one member needs to solve one problem, the length of the contest, and the number of member-problem pairs that follow.
Each of the next lines contains two integers and (, ), separated by a single space, meaning that member is able to solve problem . Every such pair appears at most once.
Output
Print one line with two integers separated by a single space: , the greatest number of problems the team can solve, and , the smallest total penalty with which those problems can be solved.
If the team cannot solve any problem, print 0 0.