Joining Cats

시간 제한2초메모리 제한2048 MB

요약
고양이 n마리가 일직선에 있고 각 바람은 정해진 세기와 방향을 가지며 만난 고양이는 합쳐질 때, k번 이내의 바람으로 모든 고양이를 하나로 합칠 수 있는지 판정한다.
난이도

어려움10점 중 8점

유형
그리디, 동적 계획법, 구현
정답자
아직 제출이 없습니다

문제

Suzukaze Aoba has a magical fan. There are nn cats sitting on a straight line. Aoba wonders if she can merge all cats into one by using the magical fan kk times.

The ii-th activation of the fan produces a gust of wind of strength exactly s_is\_i.

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 kk times.

입력

The first line contains two integers nn and kk (1≤n,k≤50001 \leq n, k \leq 5000).

The second line contains nn integers w_1,…,w_nw\_1, \ldots, w\_n (1≤w_i≤1091 \leq w\_i \leq 10^9), denoting the initial weights of the cats from left to right. No two cats initially sit on the same spot.

The third line contains kk integers s_1,…,s_ks\_1, \ldots, s\_k (1≤s_i≤1091 \leq s\_i \leq 10^9).

출력

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 kk times, or "No" otherwise.

예제4

  1. 예제 1

    입력
    5 2
    1 1 1 1 1
    2 2
    
    예상 출력
    Yes
    
  2. 예제 2

    입력
    6 7
    3 2 1 1 2 3
    2 2 2 2 2 2 2
    
    예상 출력
    No
    
  3. 예제 3

    입력
    7 4
    1 2 3 4 3 2 1
    3 3 3 3
    
    예상 출력
    Yes
    
  4. 예제 4

    입력
    5 1
    5 4 3 2 1
    10
    
    예상 출력
    Yes