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 k equals 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 and brespectively.

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
Note

In the first sample:

  • Sequence a is 11, 0, 0, 14.
  • Two of the elements are lost, and the candidates in b are 5 and 4.
  • There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".

In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.

题解:实际上如果m>1的或就直接输出yes,不要想太多,因为已经保证每个数字只出现一遍,而如果m>1的话,b中的数就必定有大小关系,所以直接输出yes。

这样一来m就只能为1了,把b放进a判断一下是否递增就可以了。

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int N=;
const int mod=1e9+;
int a[],b[];
int n,m,cnt;
int main()
{
int i,j;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]==)cnt=i;
}
for(i=;i<=m;i++)
scanf("%d",&b[i]);
if(m>){
cout<<"Yes";
return ;
}
i=cnt;
a[i]=b[];
for(i=;i<=n;i++){
if(a[i]<a[i-]){
cout<<"Yes";
return ;
}
}
cout<<"No";
return ;
}

Codeforce 814A - An abandoned sentiment from past (贪心)的更多相关文章

  1. An abandoned sentiment from past

    An abandoned sentiment from past time limit per test 1 second memory limit per test 256 megabytes in ...

  2. Codeforces Round #418 (Div. 2) A+B+C!

    终判才知道自己失了智.本场据说是chinese专场,可是请允许我吐槽一下题意! A. An abandoned sentiment from past shabi贪心手残for循环边界写错了竟然还过了 ...

  3. codeforces round 418 div2 补题 CF 814 A-E

    A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...

  4. 冬训 day2

    模拟枚举... A - New Year and Buggy Bot(http://codeforces.com/problemset/problem/908/B) 暴力枚举即可,但是直接手动暴力会非 ...

  5. Codeforce 835B - The number on the board (贪心)

    Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...

  6. codeforce Gym 100685E Epic Fail of a Genie(MaximumProduction 贪心)

    题意:给出一堆元素,求一个子集,使子集的乘积最大,如有多个,应该使子集元素个数尽量小. 题解:贪心,如果有大于1的正数,那么是一定要选的,注意负数也可能凑出大于1的正数,那么将绝对值大于1的负数两两配 ...

  7. codeforce 810B Summer sell-off (贪心 排序)

    题意: 商店准备用n天售货(每天的货物都是一样的),第i天会卖ki件货物,并且会有li个顾客来买. 如果货物没卖完, 那么每个顾客一定会买一件. 如果货物有剩, 不会保存到第二天. 现在给定一个f, ...

  8. Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)

    Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to f ...

  9. Codeforce 140C (贪心+优先队列)补题

    C. New Year Snowmen time limit per test2 seconds memory limit per test256 megabytes inputstandard in ...

随机推荐

  1. 自定义UIProgressView

    自定义CustomporgressView #import <UIKit/UIKit.h> @interface CustomporgressView : UIView @property ...

  2. 显示日期的指令: date

    1.显示日期的指令: date (1)参数: (2)实例

  3. 001-分布式理论-CAP定理

    一.概述 CAP原则又称CAP定理,指的是在一个分布式系统中,Consistency(一致性). Availability(可用性).Partition tolerance(分区容错性)这三个基本需求 ...

  4. react 首屏加载优化

    react 首屏加载优化,原本是在入口HTML文件中加载loading动画,但是部署在测试环境上的时候一直无法显示loading的部分,也是奇怪了,我们测试环境的部署一直跟本地的都不太一样,内外网的转 ...

  5. python的mutable变量与immutable变量

    python的变量分为mutable(可变的)和immutable类型. mutable:dict, list immutable:int , string , float ,tuple..

  6. [py]flask操作cookie&django的seesion和cookie机制

    浏览器同源策略(same-origin policy) csrf攻击防御核心点总结 django的cookie和session操作-7天免登录 flask操作cookie&django的see ...

  7. 异常处理的捕捉:try{}catch(异常类 变量)finally{最终执行}

    可以对异常进行针对性处理的方式.try{ //需要被检查的异常 }catch(异常类  变量)//该变量用于接收发生的异常{ //处理异常的代码 }finally{ //一定会被执行的代码. }

  8. git issue 汇总

    (1)部分: https://wiki.mahara.org/wiki/Developer_Area/Contributing_Code/Troubleshooting_your_Gerrit_con ...

  9. [Java in NetBeans] Lesson 00. Getting Set-up for Learning Java

    这个课程的参考视频在youtube. 主要学到的知识点有: set up needs Java SE JDK, NetBeans IDE class name should be the same l ...

  10. componentsSeparatedByString 的注意事项

    componentsSeparatedByString 两种情景 1. 没有分割符也生成一个数组,元素就是整个字符串本身,那你就需要判断“”这种字符串. 2. 分割的元素如果是相同的字符串,指向的是同 ...