#C7754. Bouquet Formation Challenge
Bouquet Formation Challenge
Bouquet Formation Challenge
You are given n flower beds arranged in a circle. Each flower bed contains a certain number of flowers. Your task is to determine whether there exists a contiguous segment (which may wrap around from the end to the beginning) such that the total number of flowers in that segment is at least m.
Formally, let \( n \) be the number of flower beds and an array \( a[0 \ldots n-1] \) represent the number of flowers in each bed. You need to check if there exists a segment of consecutive beds (with wrap-around allowed) whose sum is \( \geq m \).
Note: A segment can consist of any number of consecutive flower beds from 1 to \( n \).
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains two integers \( n \) and \( m \) separated by a space, where \( n \) is the number of flower beds and \( m \) is the minimum number of flowers required in a bouquet.
- The second line contains \( n \) integers separated by spaces, representing the number of flowers in each flower bed in order.
outputFormat
Output a single line to stdout containing YES
if there exists a contiguous segment (considering the circular arrangement) with a sum \( \geq m \); otherwise, output NO
.
5 10
1 2 3 4 5
YES
</p>