CF958F2.Lightsabers (medium)

普及/提高-

通过率: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.

However, since the last time, she has learned that it is not always possible to select such an interval. Therefore, she decided to ask some Jedi Knights to go on an indefinite unpaid vacation leave near certain pits on Tatooine, if you know what I mean. Help Heidi decide what is the minimum number of Jedi Knights that need to be let go before she is able to select the desired interval from the subsequence of remaining knights.

输入格式

The first line of the input contains nn ( 1<=n<=21051<=n<=2·10^{5} ) 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 Jedi Knights with lightsabers of each color from 11 to mm .

输出格式

Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output 1-1 .

输入输出样例

  • 输入#1

    8 3
    3 3 1 2 2 1 1 3
    3 1 1
    

    输出#1

    1
    
首页