Блог пользователя iron_nicko

Автор iron_nicko, история, 17 месяцев назад, По-английски

Hey, I know the contest was postponed, but I was trying to solve this question:

Question:

Consider the integer sequence A[], where the elements are first N natural numbers in order.

You are now given two integers, L and S. Determine whether there exists a subarray with length L and sum S after removing at most one element from A.

A subarray of an array is a non-empty sequence obtained by removing zero or more elements from the front of the array, and zero or more elements from the back of the array.
1 <= N <= 10^9
1 <= L <= N - 1

I came up with something like this:

My Code

Test Cases with the answers:

3
5 3 11 # YES
5 3 5 # NO
5 3 6 # YES

My code seems to pass the initial test cases, but I'd like to know if this will work for all cases. Please let me know if this is correct.

Updated Code
  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
17 месяцев назад, # |
Rev. 6   Проголосовать: нравится 0 Проголосовать: не нравится

this may help

Spoiler