Pillow Stacking
Time limit3sMemory limit1024 MB
Given N pillow softness values and a target C, decide whether a stack of pillows (none with softness C) can reach total softness C.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
Eleanor recently lost her favorite pillow. She is very particular about her pillows and sorts them by softness. The pillow she lost had softness , and she cannot sleep without this exact softness. She has access to several other types of pillows, but none of them may have softness . To work around this, she sleeps on a stack of multiple pillows.
When pillows with softness are stacked in that order, the resulting softness is
In other words, the th pillow contributes of its softness, rounded up. is the smallest integer with .
Eleanor has plenty of money and can use an unlimited number of each pillow type she has access to. Determine whether she can stack pillows to reach softness .
Input
The first line contains two integers and (, ). is the number of pillow types Eleanor has access to, and is the desired softness. The next line contains integers (), the softness of each pillow type.
Output
If Eleanor can stack pillows to reach softness , print YES. Otherwise, print NO.