#C2409. Team Formation with Skill Sum Constraints
Team Formation with Skill Sum Constraints
Team Formation with Skill Sum Constraints
You are given (N) participants with their individual skill levels. Your task is to determine whether it is possible to form exactly (M) teams such that the sum of the skill levels for each team lies within the range ([L, R]). Teams must be formed by selecting contiguous segments from the given list of participants. Each participant can be used in at most one team, and it is not necessary to use all participants.
For example, if you have 6 participants with skills [5, 10, 7, 3, 8, 9], you may choose a team from a contiguous subsequence such as [10] (with a sum of 10) and another team from another contiguous subsequence, provided both sums fall within the given bounds.
inputFormat
The first line contains four integers (N), (M), (L), and (R), where (N) is the number of participants, (M) is the required number of teams, and (L) and (R) represent the lower and upper bounds for the sum of skills in each team respectively. The second line contains (N) space-separated integers denoting the skill levels of the participants.
outputFormat
Output a single line containing either "Yes" if it is possible to form exactly (M) teams satisfying the conditions, or "No" otherwise.## sample
6 2 10 20
5 10 7 3 8 9
Yes
</p>