Codeforces Round #240 (Div. 2) A. Mashmokh and Lights
来源:互联网 发布:www.windows.com 编辑:程序博客网 时间:2024/05/17 07:45
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.
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 n space-separated integers where the i-th number is index of the button that turns the i-th light off.
5 44 3 1 2
1 1 3 4 4
5 55 4 3 2 1
1 2 3 4 5
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.
#include<iostream>#include<algorithm>using namespace std;int a[50005],b[50005],c[50005];int main(){int i,j,k,m,n;while(cin>>n>>m&&n!=0&&m!=0){for(i=1;i<=n;i++)a[i]=i;for(i=1;i<=m;i++)cin>>b[i];for(i=1;i<=m;i++)for(j=1;j<=n;j++) {if(a[j]>=b[i]&&a[j]!=0){a[j]=0; c[j]=b[i];}} for(j=1;j<n;j++) cout<<c[j]<<" "; cout<<c[n]<<endl;}}
- Codeforces Round #240 (Div. 2) A. Mashmokh and Lights
- Codeforces Round #240 (Div. 2)B. Mashmokh and Tokens
- Codeforces Round #240 (Div. 2) C. Mashmokh and Numbers
- Codeforces Round #240 (Div. 2) D. Mashmokh and ACM
- Codeforces Round #240 (Div. 2) Mashmokh and Numbers
- CodeForces 415A Mashmokh and Lights
- A. Mashmokh and Lights
- Codeforces Round #240 (Div. 1)---B.Mashmokh and ACM(dp)
- Codeforces 415A Mashmokh and Lights(水题)
- 415A Mashmokh and Lights
- cf,A. Mashmokh and Lights
- Codeforces Round #168 (Div. 2)---A. Lights Out
- Mashmokh and ACM(Codeforces Round #240)
- code forces 415A Mashmokh and Lights
- cf——A. Mashmokh and Lights
- Codeforces Round #240 (Div. 1)B---Mashmokh and ACM(水dp)
- Mashmokh and Lights
- Codeforces 414A Mashmokh and Numbers(构造)
- 整体项目开发流程
- 我该抛弃桌面程序么?
- Linux下Python代码运行--王艺桦
- 多用GCD,少用PerformSelector
- Java基础的线程概念
- Codeforces Round #240 (Div. 2) A. Mashmokh and Lights
- 【HDFS】什么叫块恢复
- Java线程同步于并发
- <Lua程序设计(第二版)>书摘-2
- TemplateMethod(模版方法)
- android开发从零开始1
- 句柄知识
- Java线程死锁的概念
- Java线程通信