Apple Tree
InterviewTime limit1sMemory limit1024 MB
Given N target heights, decide whether a 1-unit and a 2-unit watering can, used simultaneously on trees (or together on one tree), can reach exactly those heights.
- Level
Medium5 of 10
- Topics
- Greedy, Math, Implementation, Array
- Solved
- No attempts yet
Problem
Iha recently bought apple tree seeds and planted them in a row in the backyard of the farm, numbered through . All of these trees start with height .
To grow the apple trees well, Iha prepared watering cans. One watering can grows a single tree by , and the other grows a single tree by . These watering cans must be used at the same time, and a watering can cannot be used on soil with no tree. Both watering cans may be used on one tree to grow it by .
After programming the entire watering can management system, Iha was about to grow the apple trees. Just then, Gapeun came to visit and said he would like each apple tree to have a certain height. Now Iha started to worry a little, because it might be impossible to produce the arrangement of apple trees that Gapeun described using this program.
Since Iha is now busy revising the program, it is up to you to determine whether the arrangement of apple trees that Gapeun described can be produced using the two watering cans.
Input
The first line gives the natural number . () This is the number of apple trees Iha planted in the backyard.
The second line gives integers separated by spaces. () is the height Gapeun wants for the -th tree.
Output
On the first line, print “YES” if the watering cans can make every tree reach the height Gapeun wants, or “NO” otherwise, without the quotation marks.