AT_abc475_c.Walk the Line

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are NN towns arranged in a line. The towns are numbered 1,2,…,N1, 2, \ldots, N, and for each integer ii satisfying 1≤i≤N−11 \leq i \leq N-1, town ii and town i+1i + 1 are connected by a road of length AiA_i.

You are initially at town SS. You can repeatedly move between two towns connected by a road using that road.

Find the maximum possible number of towns visited in a sequence of moves such that the total distance traveled is at most LL. Here, town SS is included among the towns visited, and a town visited multiple times is counted only once.

有 NN 个城镇排成一条直线。这些城镇编号为 1,2,…,N1, 2, \ldots, N,且对每个满足 1≤i≤N−11 \leq i \leq N-1 的整数 ii,城镇 ii 与城镇 i+1i + 1 之间由一条长度为 AiA_i 的道路连接。

你初始位于城镇 SS。你可以反复利用道路在两个相连的城镇之间移动。

求在总行驶距离不超过 LL 的前提下,通过一系列移动最多能访问多少个不同的城镇。注意:起始城镇 SS 被计入已访问城镇;若某个城镇被多次访问,仅计一次。

输入格式

The input is given from Standard Input in the following format:

NN SS LL
A1A_1 A2A_2 …\ldots AN−1A_{N - 1}

输入从标准输入中按以下格式给出:

NN SS LL
A1A_1 A2A_2 …\ldots AN−1A_{N - 1}

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    6 3 10
    5 2 4 1 6

    输出#1

    4
  • 输入#2

    8 8 17
    2 3 4 4 3 5 1

    输出#2

    6
  • 输入#3

    2 1 1000000000000000000
    10000

    输出#3

    2
  • 输入#4

    9 6 28
    5 4 9 2 3 6 1 4

    输出#4

    6

说明/提示

Sample 1 Explanation:
You are initially at town 33. If you move in the order town 3→2→3→4→53 \to 2 \to 3 \to 4 \to 5, the total distance traveled is 2+2+4+1=92 + 2 + 4 + 1 = 9, and the towns visited are 2,3,4,52, 3, 4, 5, that is, four towns.

It is impossible to visit five or more towns with a total travel distance of at most 1010, so the answer for this case is 44.

Constraints

  • 2≤N≤80002 \leq N \leq 8000
  • 1≤S≤N1 \leq S \leq N
  • 0≤L≤10180 \leq L \leq 10^{18}
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • All input values are integers.

样例 1 解释:
你初始位于城镇 33。若按城镇 3→2→3→4→53 \to 2 \to 3 \to 4 \to 5 的顺序移动,则总行程距离为 2+2+4+1=92 + 2 + 4 + 1 = 9,访问过的城镇为 2,3,4,52, 3, 4, 5,即共 44 个城镇。

在总行程距离不超过 1010 的前提下,无法访问 55 个或更多城镇,因此本例的答案为 44。

约束条件

  • 2≤N≤80002 \leq N \leq 8000
  • 1≤S≤N1 \leq S \leq N
  • 0≤L≤10180 \leq L \leq 10^{18}
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页