Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <map>
- #include <set>
- #include <deque>
- #include <stack>
- #include <queue>
- #include <algorithm>
- #include <sstream>
- #include <iostream>
- #include <iomanip>
- #include <cstdio>
- #include <cmath>
- #include <cstdlib>
- #include <memory.h>
- #include <ctime>
- #include <bitset>
- #include <unordered_map>
- using namespace std;
- #define ABS(a) ((a>0)?a:-(a))
- #define MIN(a,b) ((a<b)?(a):(b))
- #define MAX(a,b) ((a<b)?(b):(a))
- #define FOR(i,a,n) for (int i=(a);i<(n);++i)
- #define FI(i,n) for (int i=0; i<(n); ++i)
- #define pnt pair <int, int>
- #define mp make_pair
- #define PI 3.1415926535897
- #define MEMS(a,b) memset(a,b,sizeof(a))
- #define LL long long
- #define U unsigned
- int a[510];
- int b[510];
- int dp[2][510][510];
- int main()
- {
- #ifdef Fcdkbear
- freopen("in.txt", "r", stdin);
- double beg = clock();
- //freopen("out.txt", "w", stdout);
- #endif
- int n,m;
- cin>>n>>m;
- FOR(i,0,n)
- cin>>a[i];
- FOR(i,0,m)
- cin>>b[i];
- MEMS(dp[0],-1);
- dp[0][0][0] = 501;
- int v = 0;
- FOR(p1,0,n)
- {
- int nv = (v^1);
- MEMS(dp[nv],-1);
- FOR(p2,0,m)
- FOR(min1,0,501)
- {
- if (dp[v][p2][min1] == -1)
- continue;
- if (min1>dp[v][p2][min1])
- continue;
- int max1 = dp[v][p2][min1];
- dp[v][p2+1][min1] = max(dp[v][p2+1][min1], max1);
- if ((b[p2]<=min1) || (b[p2]>=max1))
- continue;
- if ((p1 == n - 1) || (a[p1]>a[p1+1]))
- {
- dp[nv][p2+1][min1] = max(dp[nv][p2+1][min1], b[p2]);
- }
- else
- {
- dp[nv][p2+1][b[p2]] = max(dp[nv][p2+1][b[p2]], max1);
- }
- }
- v = nv;
- }
- FOR(p2,0,m+1)
- FOR(min1,0,501)
- if (dp[v][p2][min1]>min1)
- {
- cout<<"Yes"<<endl;
- return 0;
- }
- cout<<"No"<<endl;
- #ifdef Fcdkbear
- double end = clock();
- fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment