CF887F.Row of Models

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

时装秀的最后阶段,所有模特走上舞台并排成一列,而时装设计师则站在最右侧模特的右侧。在彩排过程中,伊莎贝拉注意到这一排并不“美观”,但她却不知如何修正。

和许多其他富有创造力的人一样,伊莎贝拉拥有自己独特的审美观。在评估模特队列的美观程度时,她关注的是每位模特的身高。她认为一排是“美观”的,当且仅当对队列中的每一位模特而言,其右侧(包括模特或时装设计师)最近的一位身高严格更矮者与她的距离不超过 kk(相邻两人之间的距离为 11,中间恰好隔一人则距离为 22,依此类推)。

她希望使该队列变得美观,但时装设计师也有自己的审美标准,因此她最多只能进行一次操作:从队列中选出两名模特并交换其位置,且仅当左侧模特的身高严格大于右侧模特的身高时才允许交换。

时装设计师(即最右侧模特右侧的那位男士)的身高比所有模特都矮,且不能被选作交换的对象。

你需要判断:是否可以通过至多一次上述类型的交换操作,使得该队列对伊莎贝拉而言变为“美观”的。

输入格式

In first line there are two integers n and k (1 ≤ n ≤ 5·105, 1 ≤ k ≤ n) — number of models and required distance.

Second line contains n space-separated integers a__i (1 ≤ a__i ≤ 109) — height of each model. Pay attention that height of fashion designer is not given and can be less than 1.

第一行包含两个整数 nn 和 kk(1≤n≤5⋅1051 \leq n \leq 5 \cdot 10^5,1≤k≤n1 \leq k \leq n)—— 模特人数和所需的间距。

第二行包含 nn 个以空格分隔的整数 aia_i(1≤ai≤1091 \leq a_i \leq 10^9)—— 每位模特的身高。注意:时装设计师的身高未给出,且可能小于 1。

输出格式

Print «YES» (without quotes) if it's possible to make row nice using at most one exchange, and «NO» (without quotes) otherwise.

如果最多进行一次交换就能使该行变得“漂亮”,则输出 «YES»(不带引号);否则输出 «NO»(不带引号)。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页