A Christmas Carol 5

View as PDF

Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

It is Christmas day and kind-hearted gentle Ebenezer Scrooge has waken up from his life of greed.
The 3 spirits of Christmas have changed his ways with great speed.
Promptly departing for the house of Bob Cratchit, he declares himself a reformed man and joins them for Christmas day lunch.
He offers a wealth of money for Bob Cratchit, to be used for Tiny Tim's health, who is playing in the corner all hunched.
"Can I join you?" asks Ebenezer Scrooge.

Ebenezer Scrooge is playing with Bob Cratchit's youngest son, Tiny Tim, and they have decided to play a fun game of dominoes! In this version of dominoes, the goal is to build a straight line of dominoes so that when the first one in the line is knocked down, it will knock down the rest of the dominoes. To make it fun for Tim, Scrooge has decided to let Tiny Tim place some domino holders at certain positions and Scrooge has to place the dominos in the holders.

To start this game off, Ebenezer Scrooge will draw a line on the ground from where the line of dominoes will start. Then Tiny Tim will set down M individual domino holders placed at position b_i from the start line, with one domino holder guaranteed to be on the start line (b_0=0). Ebenezer Scrooge has exactly N dominoes, each of some length a_i, and will attempt to place each domino in a domino holder so that when the domino at the start line is knocked down, it touches the next domino in the line, knocking it down.

A domino at position 0 with length 4 will knock down all dominoes in the range (0,4].

Given Tiny Tim's positioning of the domino holders starting, in order, from the start line and the size of each domino, is it possible for Ebenezer Scrooge to meet the goal of the game? Note that Scrooge must put a domino in every holder.

Input Specifications

The first line will contain two integers N, M where 1 \le M \le N \le 10^6.

The second line will contain N integers, a_i where 1 \le a_i \le 10^6.

The third line will contain M distinct integers, b_i where 0 \le b_i \le 10^6.

Solutions in Java are encouraged to use fast input reading.

Output Specifications

Output "yes" if Ebenezer Scrooge can knock down all the dominos or "no" otherwise.

Sample Input

4 4
2 1 4 1
0 2 3 7

Sample Output

yes

Explanation

The domino holders are positioned as such (where h is a holder and _ is an empty spot:

h_hh___h

The first holder should contain the domino of length 2, the second holder length 1, third length 4, and fourth length 1.


Comments

There are no comments at the moment.