A11427 | Row of Models
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
During the final part of fashion show all models come to the stage and stay in one row and fashion designer stays to right to model on the right. During the rehearsal, Izabella noticed, that row isn't nice, but she can't figure out how to fix it.
Like many other creative people, Izabella has a specific sense of beauty. Evaluating beauty of row of models Izabella looks at heights of models. She thinks that row is nice if for each model distance to nearest model with less height (model or fashion designer) to the right of her doesn't exceed $k$ (distance between adjacent people equals 1, the distance between people with exactly one man between them equals 2, etc).
She wants to make row nice, but fashion designer has his own sense of beauty, so she can at most one time select two models from the row and swap their positions if the left model from this pair is higher than the right model from this pair.
Fashion designer (man to the right of rightmost model) has less height than all models and can't be selected for exchange.
You should tell if it's possible to make at most one exchange in such a way that row becomes nice for Izabella.
Like many other creative people, Izabella has a specific sense of beauty. Evaluating beauty of row of models Izabella looks at heights of models. She thinks that row is nice if for each model distance to nearest model with less height (model or fashion designer) to the right of her doesn't exceed $k$ (distance between adjacent people equals 1, the distance between people with exactly one man between them equals 2, etc).
She wants to make row nice, but fashion designer has his own sense of beauty, so she can at most one time select two models from the row and swap their positions if the left model from this pair is higher than the right model from this pair.
Fashion designer (man to the right of rightmost model) has less height than all models and can't be selected for exchange.
You should tell if it's possible to make at most one exchange in such a way that row becomes nice for Izabella.
输入格式
In first line there are two integers $n$ and $k$ ( $1<=n<=5·10^{5}$ , $1<=k<=n$ ) — number of models and required distance.
Second line contains $n$ space-separated integers $a_{i}$ ( $1<=a_{i}<=10^{9}$ ) — height of each model. Pay attention that height of fashion designer is not given and can be less than 1.
Second line contains $n$ space-separated integers $a_{i}$ ( $1<=a_{i}<=10^{9}$ ) — height of each model. Pay attention that height of fashion designer is not given and can be less than 1.
输出格式
Print «YES» (without quotes) if it's possible to make row nice using at most one exchange, and «NO» (without quotes) otherwise.
输入输出样例
输入 #1
5 4 2 3 5 2 5
输出 #1
NO
输入 #2
5 2 3 6 2 2 1
输出 #2
YES
输入 #3
5 2 5 3 6 5 2
输出 #3
YES
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted