Strange Draft
InterviewTime limit1sMemory limit1024 MB
For each test case, find the K consecutive players whose best defensive ability at each of the nine positions sums to the largest total.
- Level
Medium5 of 10
- Topics
- Sliding window, Queue, Array
- Solved
- No attempts yet
Problem
In 2150, the Kureyo Baseball Organization (hereafter KBO) approved the founding of its 100th team. Until then, players were picked one at a time in zigzag order based on the previous season's standings. But as the number of teams grew, the draft took too long, so KBO announced the following new draft rules.
- The players who applied for the draft are arranged in an arbitrary order that considers factors such as school, tournament results, and physical traits.
- Each player is described by an integer (), their fixed defensive position, and an integer , their defensive ability.
- When it is a team's turn, it picks consecutive players from the list and removes those players from the list.
- The selected players must include at least one player who can play each of the nine defensive positions.
You are the manager of the Twins, who finished last the previous season. To fix the team's chronic defensive weakness, you plan to rebuild around defensive ability next season, so this draft matters a lot. You make the first pick of players.
Given the defensive position and defensive ability of each of the players, listed in the order of the applicant list, write a program that picks players so that the sum of the best defensive ability at each position is maximized. The draft is always possible.
Input
The input consists of test cases. The first line contains .
The first line of each test case contains the number of applicants and the number of players that can be picked at once, separated by a space. () Then lines follow, each containing the defensive position () and defensive ability () of each player, separated by a space.
Output
For each test case, print on its own line the maximum possible sum of the best defensive ability at each position that can be obtained in this draft.