pSortAI (CI翻译)
One day $*n*$ cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from $1$). Also each cell determined it's favourite number. On it's move $*i*$-th cell can exchange it's value with the value of some other $*j*$-th cell, if $|*i* - *j*| = *d*_{*i*}$, where $*d*_{*i*}$ is a favourite number of $*i*$-th cell. Cells make moves in any order, the number of moves is unlimited.
$*n*$ 个单元格决定进行如下游戏。初始时,每个单元格中都存放着一个与其序号相等的数字(序号从 $1$ 开始)。此外,每个单元格还确定了自己喜欢的数字。在第 $*i*$ 个单元格的回合中,如果 $|*i* - *j*| = *d*_{*i*}$,则它可以将自己的值与某个其他第 $*j*$ 个单元格中的值交换,其中 $d_i$ 是第 $i$ 个单元格喜欢的数字。单元格可以以任意顺序进行操作,操作次数不限。AI (CI翻译)The favourite number of each cell will be given to you. You will also be given a permutation of numbers from $1$ to $*n*$. You are to determine whether the game could move to this state.
现在将给出每个单元格喜欢的数字,以及一个由 $1$ 到 $*n*$ 组成的排列。请判断游戏是否能够达到给定状态。AI (CI翻译)
Input
输入
AI (CI翻译)The first line contains positive integer $*n*$ ($1 ≤ *n* ≤ 100$) — the number of cells in the array. The second line contains $*n*$ distinct integers from $1$ to $*n*$ — permutation. The last line contains $*n*$ integers from $1$ to $*n*$ — favourite numbers of the cells.
第一行包含一个正整数 $*n*$($1 ≤ *n* ≤ 100$),表示数组中单元格的数量。第二行包含 $*n*$ 个互不相同的 $1$ 到 $*n*$ 之间的整数,表示一个排列。最后一行包含 $*n*$ 个 $1$ 到 $*n*$ 之间的整数,表示各单元格喜欢的数字。AI (CI翻译)
Output
输出
AI (CI翻译)If the given state is reachable in the described game, output YES, otherwise NO.
如果给定状态可以通过上述游戏达到,输出 YES,否则输出 NO。
AI (CI翻译)
样例
5
5 4 3 2 1
1 1 1 1 1
YES
7
4 3 5 1 2 7 6
4 6 6 1 6 6 1
NO
7
4 2 5 1 3 7 6
4 6 6 1 6 6 1
YES
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。