CF1334F Strange Function
题目描述
### 题面描述
定义函数 $f$:$f(x)$ 为所有满足 $x_i>x_{1,2,\cdots,i-1}$ 的 $x_i$ 组成的序列,例如 $f[3,1,2,7,7,3,6,7,8]=[3,7,8]$。
给出两个序列 $a,b$,你可以删掉 $a$ 中的一些元素。删掉 $a_i$ 的代价为 $p_i$。你需要求出最小代价使得 $f(a)=b$ 或给出无解。
输入格式
第一行一个整数 $n\ (1\leq n\leq 5\cdot 10^5)$,表示 $a$ 的长度。
第二行 $n$ 个整数 $a_1,a_2,\cdots,a_n\ (1\leq a_i\leq n)$。
第三行 $n$ 个整数 $p_1,p_2,\cdots,p_n\ (|p_i|\leq 10^9)$。
第四行一个整数 $m\ (1\leq m\leq n)$,表示 $b$ 的长度。
第五行 $m$ 个整数 $b_1,b_2,\cdots,b_m\ (1\leq b_i\leq n,b_{i-1}
输出格式
如果答案存在,在第一行输出 $\texttt{YES}$,第二行输出最小代价。否则输出一行 $\texttt{NO}$。
translated by Alex_Wei.