One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path to escape from the museum. But Kiddo didn't want to give it back. So, Kiddo asked Conan a question. If Conan could give a right answer, Kiddo would return the ring to the museum.
Kiddo: "I have an array A A

and a number k k

, if you can choose exactly k k

elements from A A

and erase them, then the remaining array is in non-increasing order or non-decreasing order, we say A A

is a magic array. Now I want you to tell me whether A A

is a magic array. " Conan: "emmmmm..." Now, Conan seems to be in trouble, can you help him?

InputThe first line contains an integer T indicating the total number of test cases. Each test case starts with two integers n n

and k k

in one line, then one line with n n

integers: A 1 ,A 2 …A n  A1,A2…An

.
1≤T≤20 1≤T≤20

1≤n≤10 5  1≤n≤105

0≤k≤n 0≤k≤n

1≤A i ≤10 5  1≤Ai≤105

OutputFor each test case, please output "A is a magic array." if it is a magic array. Otherwise, output "A is not a magic array." (without quotes).
Sample Input

3
4 1
1 4 3 7
5 2
4 1 3 1 2
6 1
1 4 3 5 4 6

Sample Output

A is a magic array.
A is a magic array.
A is not a magic array.
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int a[maxn],b[maxn];
int main()
{
int T,N,K,cnt,pos;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&K);
rep(i,,N) scanf("%d",&a[i]);
cnt=;
rep(i,,N) pos=upper_bound(b+,b+cnt+,a[i])-b,b[pos]=a[i],cnt=max(pos,cnt);
if(cnt+K>=N) puts("A is a magic array.");
else {
reverse(a+,a+N+);
cnt=;
rep(i,,N) pos=upper_bound(b+,b+cnt+,a[i])-b,b[pos]=a[i],cnt=max(pos,cnt);
if(cnt+K>=N) puts("A is a magic array.");
else puts("A is not a magic array.");
}
}
return ;
}

HDU - 6197:array array array (简单LIS)的更多相关文章

  1. hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】

    hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组 ...

  2. Array.fill & array padding

    Array.fill & array padding arr.fill(value[, start[, end]]) https://developer.mozilla.org/en-US/d ...

  3. LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>

    LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...

  4. js Array.from & Array.of All In One

    js Array.from & Array.of All In One 数组生成器 Array.from The Array.from() static method creates a ne ...

  5. HDU 6197 array array array 2017沈阳网络赛 LIS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...

  6. hdu 6197 array array array LIS

    正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件. ac代码: #include <cstdio> #include <cstring> #include < ...

  7. hdu 6197 array array array

    array array array Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. HDU - 6197 array array array (最长上升子序列&最长下降子序列)

    题意:对于一个序列,要求去掉正好K个数字,若能使其成为不上升子序列或不下降子序列,则“A is a magic array.”,否则"A is not a magic array.\n&qu ...

  9. hdu 5280 Senior's Array

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...

随机推荐

  1. 用来在category里加属性的宏

    众所周知,一般的情况下我们是没办法在category里加属性的. 如果想加,需要用到Associated. @interface NSObject (XYFlyweightTransmit) @pro ...

  2. 异步消息postEvent更新界面

    其实就是和Qt::QueuedConnection时的信号槽一样,属于异步的. 1.新建QEvent子类 ①.头文件 #ifndef MYEVENT_H #define MYEVENT_H #incl ...

  3. Linux内核优化项

    net.ipv4.ip_forward = #该文件内容为0,表示禁止数据包转发,1表示允许 net.ipv4.conf.default.rp_filter = #是否忽略arp请求 net.ipv4 ...

  4. 数据结构(二) 树Tree

    五.树 树的定义   树的逻辑表示:树形表示法.文氏图表示法.凹入表示法.括号表示法.         结点:表示树中的元素,包括数据项及若干指向其子树的分支. 结点的度:结点拥有的子树树:树的度:一 ...

  5. git branch管理小结

    神一样膜拜此链接下http://nvie.com/posts/a-successful-git-branching-model/对git branch模型管理,以下为我的学习心得: 一.branch动 ...

  6. Node.js 项目的配置文件

    在 Node.js 中可以通过process.env来访问当前的环境变量信息,比如: { PATH: '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin', T ...

  7. ReflectionZ_测试_01

    1.Java代码 public class TreflectionZ { public static void main(String[] args) throws Exception { Class ...

  8. Spring中Bean的生命周期是怎样的

    1.Spring对Bean进行实例化(相当于程序中的new Xx()) 2.Spring将值和Bean的引用注入进Bean对应的属性中 3.如果Bean实现了BeanNameAware接口,Sprin ...

  9. tensorflow笔记:模型的保存与训练过程可视化

    tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 ...

  10. mysql 分区优缺点

    分区不一定能够提高查询速度: 原因:分区是按字段分区,如果查询条件不是分区字段会很慢.