Codeforces Round #134 (Div. 2) A. Mountain Scenery

37 篇文章 0 订阅


A. Mountain Scenery
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1)(2, y2)...(2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi andyi > yi + 1.

We shall call a vertex of a polyline with an even x coordinate a mountain peak.

The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.

Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1)(2, r2)...(2n + 1, r2n + 1).

Given Bolek's final picture, restore the initial one.

Input

The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.

It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.

Output

Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.

Sample test(s)
input
3 2
0 5 3 5 1 5 2
output
0 5 3 4 1 4 2 
input
1 1
0 2 0
output
0 1 0 
题目乍一看忒吓人,刚开始一打眼我还以为是一个几何题,结果是一个赤裸裸的水题。

题意:输入n和k两个数,接下来一行有n个数,是Little Bolek操作之后的个点的纵坐标值。n代表图上有n个顶点,你可以画一下,这样的话一共有2*n+1个点。

然后他已经经过了k次操作,任取k个山峰加1,求k次操作以前的折线各点的纵坐标。每个山峰都满足yi - 1 < yi andyi > yi + 1.

有多种结果的话,输出其中一种即可。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    int n,t,a[310];
    int i,j,k;
 while(~scanf("%d%d",&n,&k))
 {
     for(i=0;i<2*n+1;i++)
       cin>>a[i];
    for(i=0;i<2*n+1;i++)
      {
          if(k&&i%2==1&&a[i]>a[i-1]+1&&a[i]>a[i+1]+1)//只有满足这个条件才有可能是加1后的
            {
                a[i]--;
                k--;
            }
         if(i<2*n)
          printf("%d ",a[i]);
         else
          {
              printf("%d\n",a[i]);
          }

      }

 }

  return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值