Long Sequence

AtCoder
IDabc220_c
Time2000ms
Memory256MB
Difficulty
We have a sequence of $N$ positive integers: $A=(A_1,\dots,A_N)$. Let $B$ be the concatenation of $10^{100}$ copies of $A$. Consider summing up the terms of $B$ from left to right. When does the sum exceed $X$ for the first time? In other words, find the minimum integer $k$ such that: $\displaystyle{\sum_{i=1}^{k} B_i \gt X}$. ## Constraints * $1 \leq N \leq 10^5$ * $1 \leq A_i \leq 10^9$ * $1 \leq X \leq 10^{18}$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $A_1$ $\ldots$ $A_N$ $X$ [samples]
Samples
Input #1
3
3 5 2
26
Output #1
8

We have $B=(3,5,2,3,5,2,3,5,2,\dots)$.  
$\displaystyle{\sum_{i=1}^{8} B_i = 28 \gt 26}$ holds, but the condition is not satisfied when $k$ is $7$ or less, so the answer is $8$.
Input #2
4
12 34 56 78
1000
Output #2
23
API Response (JSON)
{
  "problem": {
    "name": "Long Sequence",
    "description": {
      "content": "We have a sequence of $N$ positive integers: $A=(A_1,\\dots,A_N)$.   Let $B$ be the concatenation of $10^{100}$ copies of $A$. Consider summing up the terms of $B$ from left to right. When does the sum",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc220_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a sequence of $N$ positive integers: $A=(A_1,\\dots,A_N)$.  \nLet $B$ be the concatenation of $10^{100}$ copies of $A$.\nConsider summing up the terms of $B$ from left to right. When does the sum...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments