Servers
The Greek Universities and Technological Educational Institutes Network http://www.gunet.gr has developed a cluster of web servers. Each server:
- manages the same pages,
- maintains a counter for each page, which increments by when that page is requested from the server, and
- keeps the values of these counters sorted in descending order.
Problem:
Develop a program in one of the IOI languages that, given the number of requests for each page, for each server and sorted, finds the pages with the most requests across all servers.
Example:
For servers and pages:
Explanation: The pages are numbered from to . On server , page has been requested times, page times, page times, and so on. The total requests submitted for the pages were:
For , the two most popular pages are and .
Input Files:
The input files named servers.in are text files with the following structure: The first line contains three integers , , and .
The number of hosted pages .
Note that the first page is numbered 0.
The number of servers .
The number of the most popular pages requested .
The numbers are separated in pairs by a single space.
The next lines contain pairs of integers.
The first line has for each server the page most requested, the second the next most requested, and so on.
In each pair, the first integer is the page number and the second is how many times it was requested.
All numbers are separated by a single space.
No page will be requested by any server more than times.
Output Files:
The output files named servers.out are text files with the following structure. They have exactly lines. Each line contains two integers: the page number and the total number of times it was requested. The pages are sorted in descending order of total requests (most popular first). Pages with the same total number of requests can appear in any order. Also, if the -th most popular page has the same total number of requests as the -th, it does not matter which of the two will be displayed in the output file, and which one will not be displayed at all.
Example of Input - Output Files:
STDIN (servers.in)
5 5 2
3 99 1 91 1 92 3 74 3 67
1 66 3 90 3 75 1 56 4 67
0 63 0 61 4 70 2 56 1 58
2 48 4 07 2 16 0 28 2 51
4 44 2 01 0 01 4 19 0 35
STDOUT (servers.out)
3 405
1 363
Formatting: In the output, each line terminates with a newline
character.
Maximum execution time: 1 sec.
Maximum available memory: 64 MB.
Comments