← 返回 capitalone 的题目列表First Day Index Where Cumulative Visits Reach Target
类型:online_judge
Given an array visits where visits[i] is the number of visits on day i (0-indexed), and an integer target, return the smallest index i such that the cumulative sum visits[0] + ... + visits[i] is greater than or equal to target.
If the cumulative sum never reaches target, return -1.
Input
Line 1: integer n
Line 2: n integers visits
Line 3: integer target
Output
An integer: the minimum index i meeting the condition, or -1.
Constraints
1 <= n <= 2e5
0 <= visits[i] <= 1e9
1 <= target <= 1e18
Example
Input:
5
2 3 1 2 4
7
Output:
3
Example
Input
5
2 3 1 2 4
7
Output
3