#P16700. [MCO 2026] 队伍选择

    ID: 19030 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>二分单调队列Special Judge2026笛卡尔树MCC/MCO(马来西亚)

[MCO 2026] 队伍选择

Problem Description

The dragon Evirir is a competitive flying coach. It trains NN dragon athletes, numbered 0,1,,N10, 1, \ldots, N - 1. For each ii, athlete ii has speed AiA_i.

Evirir needs to form a team for an upcoming group flying competition. Due to some strange rules, this team must be a contiguous segment of length at least KK. That is, Evirir must choose ll and rr (0lrN10 \le l \le r \le N - 1) such that Krl+1K \le r - l + 1, and form a team consisting of athletes l,l+1,,rl, l+1, \ldots, r.

The strength of a team is defined as the sum of the minimum speed and the maximum speed among the athletes on the team. Please help Evirir find a team with the maximum possible strength. If multiple teams achieve the maximum strength, Evirir prefers the one with the most athletes (because a big team looks more impressive).

Input Format

The first line contains two integers NN and KK separated by spaces.

The second line contains NN integers A0,A1,,AN1A_0, A_1, \ldots, A_{N-1} separated by spaces.

Output Format

Let mm be the maximum strength that a team can achieve, and suppose there is a team with strength mm consisting of athletes l,l+1,,rl, l+1, \ldots, r. Output three integers separated by spaces: mm, ll, and rr (0lrN10 \le l \le r \le N - 1, Krl+1K \le r - l + 1).

If there are multiple teams with maximum strength, output any one of them that has the largest possible number of athletes.

If you output the correct maximum strength and any valid team, you can still get partial credit. That is, output the correct mm, and output any integers ll and rr such that 0lrN10 \le l \le r \le N - 1 and Krl+1K \le r - l + 1. In particular, you can always output mm, 00, K1K - 1. For details about scoring, see the Scoring section.

9 3
1 2 3 3 4 3 1 5 2
7 2 5
5 2
2 2 1 2 2
4 0 1
2 1
6 7
14 1 1

Hint

Hint

Sample 1\underline{Sample\ 1}

This sample applies to subtasks 2, 4, 5, and 6.

Here there are N=9N = 9 athletes, and Evirir must choose a team with at least K=3K = 3 athletes. One optimal choice is l=2l = 2 and r=5r = 5, where the athletes' speeds are 33, 33, 44, and 33. The minimum speed is 33 and the maximum speed is 44, so the team strength is 3+4=73 + 4 = 7. Therefore the output is 7 2 5\texttt{7 2 5}.

Below are some other outputs and their results.

Output Score Explanation
7 7 8 0% This team contains fewer than 3 athletes.
4 0 2 This team strength is not the maximum possible.
7 0 2 50% The team strength is correct, even though the printed team is not correct.
7 2 4 To get full score, the team size must be as large as possible.

Sample 2\underline{Sample\ 2}

This sample applies to subtasks 2, 3, 4, 5, and 6.

Note that outputting 4 3 4\texttt{4 3 4} would also get full score, because this team also achieves the maximum possible strength 44, and the maximum possible number of athletes is also 22.

Sample 3\underline{Sample\ 3}

This sample applies to subtasks 1, 2, 4, 5, and 6.

If the team contains only one athlete, then the team strength is twice that athlete's speed, because both the minimum speed and the maximum speed come from that athlete.

Scoring

For all test cases, the input satisfies the following Constraints:

  • 1KN21051 \le K \le N \le 2 \cdot 10^5
  • For all 0iN10 \le i \le N - 1, 1Ai1091 \le A_i \le 10^9

For all subtasks, if you output the maximum strength and any valid team, you can get 50% of the score for that subtask.

Subtask Points Additional Constraints
11 88 K=1K = 1
22 1010 N5000N \le 5000
33 1414 For all 0iN10 \le i \le N - 1, Ai2A_i \le 2
44 2626 For all 0iN10 \le i \le N - 1, Ai20A_i \le 20
55 1010 For all 0iN10 \le i \le N - 1, Ai50A_i \le 50
66 3232 --

Translated by ChatGPT 5