#K77952. Gallery Painting Display
Gallery Painting Display
Gallery Painting Display
In this problem, you are given a gallery wall with a fixed available width (W) and a set of paintings to hang. Each painting has a specified width, and there are gaps (spaces) between consecutive paintings. The total width required to display the paintings is given by the formula: [ \text{Total Required Width} = \sum_{i=1}^{n} \text{width}i + \sum{i=1}^{n-1} \text{gap}_i ] For each test case, if the total required width is less than or equal to (W), then it is possible to display all the paintings; otherwise, it is not.
Your task is to determine for each test case whether the paintings can be arranged within the available width. Output "YES" if they can be displayed and "NO" otherwise.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (t) representing the number of test cases. For each test case:
- The first line contains two integers (W) and (n), where (W) is the available width of the gallery wall, and (n) is the number of paintings.
- The second line contains (n) integers: the widths of the paintings.
- If (n > 1), the third line contains (n-1) integers representing the gaps between each pair of consecutive paintings. If (n = 1), no gap line is provided.
outputFormat
For each test case, output a single line containing either "YES" if the paintings can be displayed on the gallery wall without exceeding (W), or "NO" otherwise. The results for different test cases should be printed on separate lines (stdout).## sample
2
100 3
30 30 30
5 5
50 2
20 30
10
YES
NO
</p>