CF958F1.Lightsabers (easy)

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

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 n Jedi Knights standing in front of her, each one with a lightsaber of one of m 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 _k_1 knights with lightsabers of the first color, _k_2 knights with lightsabers of the second color, ..., k__m knights with lightsabers of the m-th color. Help her find out if this is possible.

银河议会局势动荡,数千个恒星系已宣布意图脱离共和国。海蒂大师需要挑选绝地武士,派遣他们前往银河系各处执行维和任务。众所周知,任何维和任务的成功与否,取决于参与该任务的绝地武士光剑的颜色组合。

海蒂面前站着 nn 名绝地武士,每人手持一把 mm 种可能颜色之一的光剑。她深知:为使任务效果达到最佳,必须选出一段连续区间的武士,使得其中恰好有 k1k_1 名武士持有第一种颜色的光剑,k2k_2 名武士持有第二种颜色的光剑,……,kmk_m 名武士持有第 mm 种颜色的光剑。请帮她判断是否存在满足条件的区间。

输入格式

The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers _k_1, _k_2, ..., k__m (with ) – the desired counts of lightsabers of each color from 1 to m.

输入的第一行包含两个整数 nn(1≤n≤1001 \leq n \leq 100)和 mm(1≤m≤n1 \leq m \leq n)。
第二行包含 nn 个整数,取值范围为 {1,2,…,m}\{1, 2, \dots, m\},表示后续绝地武士的光剑颜色。
第三行包含 mm 个整数 k1,k2,…,kmk_1, k_2, \dots, k_m(满足 ),即颜色 11 至 mm 的光剑所需数量。

输出格式

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

如果存在一个满足指定颜色计数的区间,则输出 YES;否则(即不存在这样的区间),输出 NO。

输入输出样例

  • 输入#1

    5 2
    1 1 2 2 1
    1 2

    输出#1

    YES

输入解题思路,AI测评打分。不知道怎么写?

首页