#abc220c. C - Long Sequence

C - Long Sequence

Score : 300300 points

问题描述

我们有一个包含 NN 个正整数的序列:A=(A1,,AN)A=(A_1,\dots,A_N)

BBAA 的重复串联,重复次数为 1010010^{100} 次。

从左至右计算序列 BB 中各项之和。何时和首次超过 XX

换句话说,找到满足以下条件的最小整数 kk

i=1kBi>X\displaystyle{\sum_{i=1}^{k} B_i \gt X}

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a sequence of NN positive integers: A=(A1,,AN)A=(A_1,\dots,A_N).
Let BB be the concatenation of 1010010^{100} copies of AA.

Consider summing up the terms of BB from left to right. When does the sum exceed XX for the first time?
In other words, find the minimum integer kk such that:

i=1kBi>X\displaystyle{\sum_{i=1}^{k} B_i \gt X}.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • 1X10181 \leq X \leq 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 \ldots ANA_N

XX

Output

Print the answer.

Sample Input 1

3
3 5 2
26

Sample Output 1

8

We have B=(3,5,2,3,5,2,3,5,2,)B=(3,5,2,3,5,2,3,5,2,\dots).
i=18Bi=28>26\displaystyle{\sum_{i=1}^{8} B_i = 28 \gt 26} holds, but the condition is not satisfied when kk is 77 or less, so the answer is 88.

Sample Input 2

4
12 34 56 78
1000

Sample Output 2

23

update @ 2024/3/10 09:43:13