Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 777;
- int a[N], b[N];
- int dp[N][N];
- int main() {
- int n, m;
- scanf("%d %d", &n, &m);
- for (int i = 0; i < n; i++) {
- scanf("%d", a + i);
- }
- for (int i = 0; i < m; i++) {
- scanf("%d", b + i);
- }
- for (int i = 0; i < n; i++) {
- for (int from = 1; from <= m; from++) {
- dp[i][from] = (i > 0 ? (from - 1) : m);
- }
- }
- for (int pos = 0; pos < m; pos++) {
- for (int i = n - 1; i >= 0; i--) {
- for (int from = 1; from <= b[pos]; from++) {
- int to = dp[i][from];
- if (to < b[pos]) {
- continue;
- }
- if (i == n - 1) {
- puts("Yes");
- return 0;
- }
- int nfrom = from;
- int nto = to;
- if (a[i] < a[i + 1]) {
- nfrom = b[pos] + 1;
- } else {
- nto = b[pos] - 1;
- }
- if (1 <= nfrom && nfrom <= nto && nto <= m) {
- dp[i + 1][nfrom] = max(dp[i + 1][nfrom], nto);
- }
- }
- }
- }
- puts("No");
- return 0;
- }
Add Comment
Please, Sign In to add comment