#P15524. [ROIR 2015 Day 1] prizes 奖品选择

[ROIR 2015 Day 1] prizes 奖品选择

Problem Description

Alisa and Bob became the winners of a TV quiz show, and now they need to choose prizes. There are nn prizes, numbered from 11 to nn.

The prize selection rules are as follows: The organizer gives a positive integer kk (1≤k≤n/31 \leq k \leq n / 3). First, Alisa chooses kk consecutive prize indices. Then, Bob chooses kk consecutive prize indices, but he cannot choose any index that Alisa has already chosen. After that, the winners receive the prizes they selected.

Alisa knows Bob very well, and she knows how much each prize is worth to Bob (this is a positive integer). Alisa does not like Bob, so when choosing prizes, she wants to make the total value of the prizes Bob chooses as small as possible. Alisa does not care which prizes she gets.

Task: Write a program that, given the prize values and the value of kk, determines the minimum total value xx that Alisa can guarantee, so that the total value of the prizes Bob chooses will not exceed xx.

Input Format

The first line of the input file contains two integers: nn —— the total number of prizes, and kk —— the number of consecutive prizes each winner must choose (3≤n≤1000003 \leq n \leq 100 000, 1≤k≤n/31 \leq k \leq n / 3).

The second line contains nn integers: a1,a2,...,ana_1, a_2, ..., a_n, where aia_i is the value of the ii-th prize to Bob (1≤ai≤1091 \leq a_i \leq 10^9).

Output Format

The output file should contain one integer —— the minimum xx such that Alisa can make the total value of the prizes Bob chooses not exceed xx.

10 2
1 2 4 5 2 4 2 2 1 6
7

Hint

Explanation of the Example

In this example, Alisa can choose prizes 44 and 55. Then Bob can choose prizes 99 and 1010, and the total value he gets is 77.

Scoring System and Subtasks

Subtask 1 (30 points)

3≤n≤503 \leq n \leq 50, 1≤ai≤1051 \leq a_i \leq 10^5.

Subtask 2 (30 points)

3≤n≤50003 \leq n \leq 5000, 1≤ai≤1051 \leq a_i \leq 10^5.

Subtask 3 (40 points)

3≤n≤1000003 \leq n \leq 100 000, 1≤ai≤1091 \leq a_i \leq 10^9.

Translation source: GPT 5.2.

Translated by ChatGPT 5