Codeforces Round #418 A--An abandoned sentiment from past

A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.

To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.

Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length kequals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.

If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.

Input

The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a andb respectively.

The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.

The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence.

Input guarantees that apart from 0, no integer occurs in a and b more than once in total.

Output

Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.

Examples
input
4 2
11 0 0 14
5 4
output
Yes
input
6 1
2 3 0 8 9 10
5
output
No
input
4 1
8 94 0 4
89
output
Yes
input
7 7
0 0 0 0 0 0 0
1 2 3 4 5 6 7
output
Yes

题意就是把b数组插到a数组的0中
只有有一个不是递增序列,那就输出Yes
所以我们把b按照递减序列排序
只要b递减后 a还是递增 那这个序列就递增 反之递减

 1 #include <cctype>
 2 #include <cstdio>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 
 7 const int MAXN=1010;
 8 
 9 int n,m;
10 
11 int a[MAXN],b[MAXN],q[MAXN];
12 
13 inline void read(int&x) {
14     int f=1;register char c=getchar();
15     for(x=0;!isdigit(c);c=='-'&&(f=-1),c=getchar());
16     for(;isdigit(c);x=x*10+c-48,c=getchar());
17     x=x*f;
18 }
19 
20 inline bool cmp(int a,int b) {
21     return a>b;
22 }
23 
24 int hh() {
25     int t=0;
26     read(n);read(m);
27     for(int i=1;i<=n;++i) read(a[i]);
28     for(int i=1;i<=m;++i) read(b[i]);
29     sort(b+1,b+1+m,cmp);
30     for(int i=1;i<=n;++i) if(!a[i]) a[i]=b[++t];
31     for(int i=1;i<n;++i) 
32       if(a[i]>a[i+1]) {
33           printf("Yes\n");
34           return 0;
35       }
36     printf("No\n");
37     return 0;
38 }
39 
40 int sb=hh();
41 int main(int argc,char**argv) {}
代码

 



---恢复内容结束---

posted @ 2017-09-05 11:36  拿叉插猹哈  阅读(130)  评论(0编辑  收藏  举报