Joining Cats
시간 제한2초메모리 제한2048 MB
고양이 n마리가 일직선에 있고 각 바람은 정해진 세기와 방향을 가지며 만난 고양이는 합쳐질 때, k번 이내의 바람으로 모든 고양이를 하나로 합칠 수 있는지 판정한다.
문제
Suzukaze Aoba has a magical fan. There are cats sitting on a straight line. Aoba wonders if she can merge all cats into one by using the magical fan times.
The -th activation of the fan produces a gust of wind of strength exactly .
For each gust of wind, Aoba picks its starting position and direction (eastward or westward). Then the gust of wind starts moving continuously in that direction with constant speed. Aoba can decide to turn the fan off at any moment, in which case, the wind disappears.
When the gust of wind encounters a cat, if the weight of the cat is strictly larger than the strength of the wind, the fan turns off automatically. Otherwise, the cat will be continuously pushed to the direction the wind is blowing.
When two cats meet, they merge into a cat whose weight is equal to the sum of their weights. The above rules then apply to the newly merged cat.
Determine if joining all cats is possible by using the fan at most times.
입력
The first line contains two integers and ().
The second line contains integers (), denoting the initial weights of the cats from left to right. No two cats initially sit on the same spot.
The third line contains integers ().
출력
Print a line with one word (case-sensitive): "Yes" if it is possible to merge all cats into one by using the magical fan at most times, or "No" otherwise.