Codeforces Round #240 (Div. 2)->A. Mashmokh and Lights

A. Mashmokh and Lights
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mashmokh works in a factory. At the end of each day he must turn off all of the lights.

The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.

Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed mdistinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.

Please, help Mashmokh, print these indices.

Input

The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).

It is guaranteed that all lights will be turned off after pushing all buttons.

Output

Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.

Examples
input
5 4
4 3 1 2
output
1 1 3 4 4 
input
5 5
5 4 3 2 1
output
1 2 3 4 5 
Note

In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.

 题意:按了某个按键a[i],>=a[i]的数字的灯都会被关掉(如果那只灯已经关了就不记录,也就是每个关的灯输出的都是让它第一次关的数字,做个标记就行了),输出第i只灯是按哪只灯时关掉的。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n,m;
 6     cin>>n>>m;
 7     int a[101],b[101]= {0};
 8     for(int i=0; i<m; i++)
 9     {
10         cin>>a[i];
11         for(int j=a[i]-1; j<n; j++)
12         {
13             if(b[j]==0)
14                 b[j]=a[i];
15         }
16     }
17     for(int i=0; i<n; i++)
18     {
19         printf("%d%c",b[i],i==n-1?'\n':' ');
20     }
21     return 0;
22 }

 

转载于:https://www.cnblogs.com/zhien-aa/p/5682999.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值