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 211 0 0 145 4

output

Yes

input

6 12 3 0 8 9 105

output

No

input

4 18 94 0 489

output

Yes

input

7 70 0 0 0 0 0 01 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) {}

代码


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

时间: 2024-08-30 11:25:45

Codeforces Round #418 A--An abandoned sentiment from past的相关文章

loj #6091. 「Codeforces Round #418」幻想特快

#6091. 「Codeforces Round #418」幻想特快 1 #include<algorithm> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdio> 5 #include<queue> 6 using namespace std; 7 #define maxn 10000 8 int n,a[maxn],b[maxn],p[maxn],nxt1,nxt2,tot,

Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection(双指针)

题目链接:Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection 题意: 给你一个字符串,有q个询问,每个询问一个x和一个字符 o. 现在让你在原来的字符串上最多改变x个字符,问能构成最长的o子串的长度. 题解: 一共有26*1500种状态,对于每个状态用双指针滚一滚就行了. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=(a);i<

codeforces round 418 div2 补题 CF 814 A-E

A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300],b[300],n,k; bool cmp(int a,int b) { return a>b; } int main() {//freopen("t.txt","r",stdin); scanf("%d%d",&n,&k); f

Codeforces Round #418 (Div. 2)

A - An abandoned sentiment from past 由于所有的数组B内所有的数都不同,因此当k > 1是就可以使该序列不递增 当k = 1是,带入B[0],判断序列A是否递增就可以啦 #include <bits/stdc++.h> using namespace std; const int MAXN = 100008; int a[MAXN], b[MAXN]; int main() { int n, k; scanf("%d%d", &am

Codeforces Round #418 C

C An impassioned circulation of affection 题意:给一个长度为n的字符串,q个询问,询问若将任意m个字符替换成任意字符,可以得到的最长的连续的c是多少 思路:询问20w,字符串长度1500,其实只有1500*26个询问是有效的,其他询问都是重复的,所以预处理出每个字符1-n的答案,询问时直接输出就可以了,预处理用尺取法,用t表示当前答案,u表示当前还可以替换几个字符,每次往前尺取,若当前字符为c则t++,否则若u>0 则 t++ 且 u--(使用了一次替换

Codeforces Round #418 B

An express train to reveries 题意:给2长度为n的数列a b,a b中至少存在一个i使得ai!=bi,构造一个数列p,使得恰好存在一个i使得ai!=pi,且恰好存在一个j使得aj!=pj,且p里面的数为1-n且无重复,输出p,保证有解 思路:题目保证有解,可知,最多存在2个i使得ai!=bi,最少一个,如果只有一个,那么好办,令p=a,将pi换成1-n中没有出现的那个数就可以了,如果有存在2个不等的数,那么令p=a(除开两个ai!=bi的位置),找出未出现的2个数,将

Codeforces Round #418 (Div. 2)D

给n个圆要么包含,要么相分离,没有两个公共点,当成一棵树,把包含的面积大的放在上面 如图最上面的par记为-1,level记为0,当par==-1||level==1时就加否则减, 就是第一,二层先加,第三层减,然后后面的一直交替就行了 #include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #includ

Codeforces Round #418 (Div. 2) C

Description Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it! Still unsatisfied with the garland, Nadeko

loj #6090. 「Codeforces Round #418」尘封思绪

https://loj.ac/problem/6090 1 #include<algorithm> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdio> 5 #include<cmath> 6 #include<queue> 7 using namespace std; 8 #define maxn 10900 9 int n,k,a[maxn],b[maxn],cnt