CF958F1.Lightsabers (easy)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.

Heidi has nn Jedi Knights standing in front of her, each one with a lightsaber of one of mm possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1k_{1} knights with lightsabers of the first color, k2k_{2} knights with lightsabers of the second color, ...... , kmk_{m} knights with lightsabers of the mm -th color. Help her find out if this is possible.

输入格式

The first line of the input contains nn ( 1<=n<=1001<=n<=100 ) and mm ( 1<=m<=n1<=m<=n ). The second line contains nn integers in the range 1,2,...,m{1,2,...,m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains mm integers k1,k2,...,kmk_{1},k_{2},...,k_{m} (with ) – the desired counts of lightsabers of each color from 11 to mm .

输出格式

Output YES if an interval with prescribed color counts exists, or output NO if there is none.

输入输出样例

  • 输入#1

    5 2
    1 1 2 2 1
    1 2
    

    输出#1

    YES
    
首页