codeforces problem/415/A
来源:互联网 发布:原生js实现分页效果 编辑:程序博客网 时间:2024/05/16 07:04
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 <stdio.h>#include <string.h>#include <iostream>using namespace std;struct note{ int y,z;}edge[105];int a[105];int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { for(int i=0;i<=n;i++) edge[i].z=edge[i].y=0; for(int i=1;i<=m;i++) { scanf("%d",&a[i]); for(int j=a[i];j<=n;j++) { if(edge[j].z==0) { edge[j].z=1; edge[j].y=a[i]; } } } for(int i=1;i<=n;i++) printf(i==n?"%d\n":"%d ",edge[i].y); } return 0;}
- codeforces problem/415/A
- Problem - 152A - Codeforces
- codeforces problem/244/A
- codeforces. problem/408/A
- Codeforces Problem 333A
- Codeforces Problem 332A
- codeforces problem/416/A 二分
- codeforces 17A Noldbach problem
- 【codeforces 29A】Spit Problem
- CodeForces - 29A - Spit Problem
- CodeForces-17A-Noldbach problem
- 【codeforces 749A】Bachgold Problem
- Codeforces 749A-Bachgold Problem
- Problem--1A--Codeforces--TheatreSquare
- Problem--4A--Codeforces--Watermelon
- Problem--231A--Codeforces--Team
- Problem--282A--Codeforces--BIt++
- Problem--96A--Codeforces--Football
- goldengate extract为何停止工作,但不报错,如何解决?
- word页码倒排
- IT博文推荐
- 黑马程序员---內省、注解与类加载器
- c++prime重学(三)基于第四版
- codeforces problem/415/A
- Python+Django+SAE系列教程4-----操作文件
- Spring mvc中@RequestMapping 6个基本用法小结
- eth0,eth1,eth2,lo是什么意思?
- 黑马程序员--- 正则表达式
- 第6周作业3-Fibonacci数列(网络131黄宇倩)
- 如何在Linux下安装和配置phpMyAdmin?
- 探究中水回用工艺中反渗透装置的操作工艺
- 关于函数返回值的一些见解