F1. Lightsabers (easy)

Codeforces
IDCF958F1
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
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. ## Input 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_. ## Output Output _YES_ if an interval with prescribed color counts exists, or output _NO_ if there is none. [samples]
银河议会中出现了动荡。数千个恒星系统已宣布打算脱离共和国。海迪大师需要挑选出前往全银河执行维和任务的绝地武士。众所周知,任何维和任务的成功都取决于参与任务的绝地武士光剑的颜色。 海迪面前有 #cf_span[n] 名绝地武士站成一排,每人持有一把颜色属于 #cf_span[m] 种可能颜色之一的光剑。她知道,为了使任务最有效,她需要选择一个连续的武士区间,使得其中恰好有 #cf_span[k1] 名武士的光剑为第一种颜色,#cf_span[k2] 名武士的光剑为第二种颜色,#cf_span[...],#cf_span[km] 名武士的光剑为第 #cf_span[m] 种颜色。请帮助她判断这是否可能。 输入的第一行包含 #cf_span[n] (#cf_span[1 ≤ n ≤ 100]) 和 #cf_span[m] (#cf_span[1 ≤ m ≤ n])。第二行包含 #cf_span[n] 个整数,范围在 #cf_span[{1, 2, ..., m}] 内,表示后续绝地武士光剑的颜色。第三行包含 #cf_span[m] 个整数 #cf_span[k1, k2, ..., km](满足 )——表示从颜色 #cf_span[1] 到 #cf_span[m] 每种颜色所需的光剑数量。 如果存在一个满足指定颜色数量的区间,则输出 _YES_;否则输出 _NO_。 ## Input 输入的第一行包含 #cf_span[n] (#cf_span[1 ≤ n ≤ 100]) 和 #cf_span[m] (#cf_span[1 ≤ m ≤ n])。第二行包含 #cf_span[n] 个整数,范围在 #cf_span[{1, 2, ..., m}] 内,表示后续绝地武士光剑的颜色。第三行包含 #cf_span[m] 个整数 #cf_span[k1, k2, ..., km](满足 )——表示从颜色 #cf_span[1] 到 #cf_span[m] 每种颜色所需的光剑数量。 ## Output 如果存在一个满足指定颜色数量的区间,则输出 _YES_;否则输出 _NO_。 [samples]
**Definitions** Let $ n, m \in \mathbb{Z}^+ $ with $ 1 \leq m \leq n \leq 100 $. Let $ C = (c_1, c_2, \dots, c_n) $ be a sequence of integers where $ c_i \in \{1, 2, \dots, m\} $, representing the lightsaber colors of the $ n $ Jedi Knights. Let $ K = (k_1, k_2, \dots, k_m) \in \mathbb{Z}^m $ be the target count vector, where $ k_j \geq 0 $ is the desired number of Jedi with lightsaber color $ j $. **Constraints** 1. $ 1 \leq n \leq 100 $ 2. $ 1 \leq m \leq n $ 3. $ 1 \leq c_i \leq m $ for all $ i \in \{1, \dots, n\} $ 4. $ k_j \geq 0 $ for all $ j \in \{1, \dots, m\} $, and $ \sum_{j=1}^m k_j \leq n $ **Objective** Determine whether there exists a contiguous subarray (interval) $ C[i:j] = (c_i, c_{i+1}, \dots, c_j) $ for some $ 1 \leq i \leq j \leq n $, such that for each color $ \ell \in \{1, \dots, m\} $, the number of occurrences of $ \ell $ in $ C[i:j] $ is exactly $ k_\ell $. That is, define for any subarray $ C[i:j] $: $$ f_\ell(i,j) = \left| \{ p \in \{i, \dots, j\} \mid c_p = \ell \} \right| $$ Then, output **YES** if there exists $ (i,j) $ such that $ f_\ell(i,j) = k_\ell $ for all $ \ell \in \{1, \dots, m\} $; otherwise, output **NO**.
Samples
Input #1
5 2
1 1 2 2 1
1 2
Output #1
YES
API Response (JSON)
{
  "problem": {
    "name": "F1. Lightsabers (easy)",
    "description": {
      "content": "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 m",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF958F1"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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 m...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "银河议会中出现了动荡。数千个恒星系统已宣布打算脱离共和国。海迪大师需要挑选出前往全银河执行维和任务的绝地武士。众所周知,任何维和任务的成功都取决于参与任务的绝地武士光剑的颜色。\n\n海迪面前有 #cf_span[n] 名绝地武士站成一排,每人持有一把颜色属于 #cf_span[m] 种可能颜色之一的光剑。她知道,为了使任务最有效,她需要选择一个连续的武士区间,使得其中恰好有 #cf_span[k1]...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ with $ 1 \\leq m \\leq n \\leq 100 $.  \nLet $ C = (c_1, c_2, \\dots, c_n) $ be a sequence of integers where $ c_i \\in \\{1, 2, \\dots, m\\} $, representing the...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments