#P5892. [IOI 2014] holiday 假期

[IOI 2014] holiday 假期

Description

Jianjia is planning a trip to Taiwan for the next vacation. During this vacation, Jianjia will travel between cities and visit attractions in those cities.

There are nn cities in Taiwan, all located along a single highway. The cities are numbered consecutively from 00 to n1n-1.

For city ii (0<i<n10 < i < n-1), its neighboring cities are i1i-1 and i+1i+1. For city 00, the only neighboring city is 11. For city n1n-1, the only neighboring city is n2n-2.

Each city has some attractions. Jianjia has dd days of vacation and wants to visit as many attractions as possible. He has already chosen the first city to visit at the start of the vacation. On each day of the vacation, Jianjia can either move to a neighboring city, or visit all attractions in the current city, but not both. Even if Jianjia stays in the same city multiple times, he will not visit the attractions of that city again. Please help Jianjia plan this vacation so that he can visit as many attractions as possible.

Input Format

  • Line 11: Three non-negative integers, where nn is the number of cities, start\text{start} is the index of the starting city, and dd is the number of vacation days.
  • Line 22: nn non-negative integers a0,a1,,an1a_0,a_1,\cdots, a_{n-1}. For 0in10 \le i \le n-1, aia_i is the number of attractions in city ii.

Output Format

  • One line: the maximum number of attractions that can be visited.
5 2 7
10 2 20 30 1

60

Hint

Subtasks

In all subtasks, 0d2n+n20 \le d \le 2n+\lfloor\frac n2\rfloor. Also, the number of attractions in each city is a non-negative integer.

Subtask Score nn Maximum attractions in each city Starting city
11 77 2n202 \le n \le 20 10910^9 No restriction
22 2323 2n1052 \le n \le 10^5 100100 City 00
33 1717 2n3×1032 \le n \le 3 \times 10 ^3 10910^9 No restriction
44 5353 2n1052 \le n \le 10^5

Translated by ChatGPT 5