#K65147. Exact Fruit Collection from Consecutive Trees

    ID: 32133 Type: Default 1000ms 256MiB

Exact Fruit Collection from Consecutive Trees

Exact Fruit Collection from Consecutive Trees

In this problem, you are given a sequence of trees, each producing a certain number of fruits. The goal is to determine whether there exists a contiguous segment of trees (with a length of at most (k)) such that the total number of fruits collected is exactly (m). Formally, given an array (f) of length (n), you need to decide if there exists an index (i) and a length (L) (where (1 \leq L \leq k)) such that:

[ \sum_{j=i}^{i+L-1} f_j = m ]

If such a subarray exists, output YES; otherwise, output NO.

Input/Output Flow: The program reads input from stdin and prints the result to stdout.

inputFormat

The first line contains three integers (n), (m), and (k) separated by spaces, where (n) is the number of trees, (m) is the exact number of fruits to collect, and (k) is the maximum number of consecutive trees you can pick. The second line contains (n) integers representing the number of fruits each tree produces, in order.

outputFormat

Output a single line containing either YES if there exists a contiguous subarray of length at most (k) that sums exactly to (m), or NO otherwise.## sample

5 15 3
3 10 2 5 6
YES