#C9020. Top K Most Accessed Resources

    ID: 53068 Type: Default 1000ms 256MiB

Top K Most Accessed Resources

Top K Most Accessed Resources

Given a list of access logs where each log is represented as a triple \( (user\_id, resource, timestamp) \), and given a time interval \( [start\_time, end\_time] \) along with an integer \( k \), your task is to determine the top \( k \) most accessed resources in that time period. The ranking is determined primarily by the number of accesses. In case of ties (i.e. resources with an equal number of accesses), the resource that appears earlier in the logs is ranked higher.

Formally, if a resource \( i \) is accessed \( c_i \) times within the time window, you must return the resources with the highest counts, sorted in non-increasing order. If there are fewer than \( k \) resources, return all of them.

Note: All timestamps are integers. The input is provided via standard input and the output should be printed to standard output.

inputFormat

The input is read from standard input. The first line contains an integer ( n ) representing the number of log entries. Each of the next ( n ) lines contains three fields separated by spaces: a user ID (string), a resource (string), and a timestamp (integer). The next line contains two integers: ( start_time ) and ( end_time ), indicating the inclusive time range. The last line contains an integer ( k ), the number of top resources to output.

outputFormat

Print the top ( k ) most accessed resources in the specified time period on a single line separated by a single space. If no resources are accessed in the given period, print an empty line.## sample

2
user1 resource1 1
user2 resource2 2
1 2
1
resource1

</p>