This is an easier version of the problem. In this version n≤1000n≤1000

The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company has already bought nn plots along the highway and is preparing to build nn skyscrapers, one skyscraper per plot.

Architects must consider several requirements when planning a skyscraper. Firstly, since the land on each plot has different properties, each skyscraper has a limit on the largest number of floors it can have. Secondly, according to the design code of the city, it is unacceptable for a skyscraper to simultaneously have higher skyscrapers both to the left and to the right of it.

Formally, let's number the plots from 11 to nn . Then if the skyscraper on the ii -th plot has aiai floors, it must hold that aiai is at most mimi (1≤ai≤mi1≤ai≤mi ). Also there mustn't be integers jj and kk such that j<i<kj<i<k and aj>ai<akaj>ai<ak . Plots jj and kk are not required to be adjacent to ii .

The company wants the total number of floors in the built skyscrapers to be as large as possible. Help it to choose the number of floors for each skyscraper in an optimal way, i.e. in such a way that all requirements are fulfilled, and among all such construction plans choose any plan with the maximum possible total number of floors.

Input

The first line contains a single integer nn (1≤n≤10001≤n≤1000 ) — the number of plots.

The second line contains the integers m1,m2,…,mnm1,m2,…,mn (1≤mi≤1091≤mi≤109 ) — the limit on the number of floors for every possible number of floors for a skyscraper on each plot.

Output

Print nn integers aiai  — the number of floors in the plan for each skyscraper, such that all requirements are met, and the total number of floors in all skyscrapers is the maximum possible.

If there are multiple answers possible, print any of them.

Examples
Input

 
5
1 2 3 2 1
Output

 
1 2 3 2 1 
Input

 
3
10 6 8
Output

 
10 6 6 
大意是让你填在n个位置填数,有两个限制:1.每个位置的数不能超过那个位置的最大范围。2.填的数的左右两边不能有比它大的数。
简单版暴力就可以过,枚举1e3个位置,可以看出是一个类似尖峰的形状,分别往两边递减,找到那个能取最大值的位置,输出即可。O(n^2)复杂度对于1e3可过。
不开long long见祖宗!!!
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int a[];
int out[];
int main()
{
int n,i,j,k;
cin>>n;
int num=-;
long long ans=;
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=;i<=n;i++)
{
long long cnt=;
cnt+=a[i];
out[i]=a[i];
for(j=i-;j>=;j--)
{
cnt+=min(a[j],out[j+]);
out[j]=min(a[j],out[j+]);
}
for(j=i+;j<=n;j++)
{
cnt+=min(a[j],out[j-]);//在两个限制之下取最小的
out[j]=min(a[j],out[j-]);
}
if(cnt>=ans)
{
num=i;
ans=cnt;
}
}
out[num]=a[num];
for(j=num-;j>=;j--)
{
out[j]=min(a[j],out[j+]);
}
for(j=num+;j<=n;j++)
{
out[j]=min(a[j],out[j-]);
}
for(i=;i<=n;i++)
{
cout<<out[i]<<' ';
}
return ;
}

Codeforces Round #622 (Div. 2) C1. Skyscrapers (easy version)(简单版本暴力)的更多相关文章

  1. Codeforces Round #622(Div 2) C1. Skyscrapers (easy version)

    题目链接: C1. Skyscrapers (easy version) 题目描述: 有一行数,使得整个序列满足 先递增在递减(或者只递增,或者只递减) ,每个位置上的数可以改变,但是最大不能超过原来 ...

  2. Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)

    Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...

  3. Codeforces Round #622 (Div. 2).C2 - Skyscrapers (hard version)

    第二次写题解,请多多指教! http://codeforces.com/contest/1313/problem/C2 题目链接 不同于简单版本的暴力法,这个数据范围扩充到了五十万.所以考虑用单调栈的 ...

  4. Codeforces Round #622 (Div. 2) C2 - Skyscrapers (hard version) 单调栈

    从左往右扫,找到比第i个小的第一个数字,l[i] = l[last] + (i - last) * m[i],用单调栈O(n)维护这个过程,再从右往左扫,同理可以算出r数组,注意一下long long ...

  5. Codeforces Round #622 (Div. 2)C2 Skyscrapers最大"尖"性矩形,思维||分治

    题:https://codeforces.com/contest/1313/problem/C2 题意:给出n个数,分别代表第i个位置所能搭建的最大高度,问以哪一个位置的塔的高度为基准向左的每一个塔都 ...

  6. Codeforces Round #570 (Div. 3) E. Subsequences (easy version) (搜索,STL)

    题意:有一长度为\(n\)的字符串,要求得到\(k\)不同的它的子序列(可以是空串),每个子序列有\(|n|-|t|\)的贡献,求合法情况下的最小贡献. 题解:直接撸个爆搜找出所有子序列然后放到set ...

  7. Codeforces Round #622 (Div. 2) 1313 C1

    C1. Skyscrapers (easy version) time limit per test1 second memory limit per test512 megabytes inputs ...

  8. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  9. Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)

    Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...

随机推荐

  1. Django_发邮件

    1. 设置项

  2. switch case理解

    第一个:分类的思想  ;  第二个就是灵活切换到那一路分支的作用

  3. [HNOI2017] 礼物 - 多项式乘法FFT

    题意:给定两个 \(n\) 元环,环上每个点有权值,分别为 \(x_i, y_i\).定义两个环的差值为 \[\sum_{i=0}^{n-1}{(x_i-y_i)^2}\] 可以旋转其中的一个环,或者 ...

  4. STM32------SYSCLK

    重要的时钟:PLLCLK,  SYSCLK,  HCKL,   PCLK1,   PCLK2  之间的关系要弄清楚; 1.HSI:高速内部时钟信号 stm32单片机内带的时钟(8M频率)精度较差2.H ...

  5. Idea实用小Tips

    设置keymap 自己根据习惯选择keymap(键位) 插件安装 ###省去set.get方法以及基于注解的日志框架 lombok plugin ###找bug用的 FindBugs-IDEA ### ...

  6. slice 实现原理

    package main /* #include <stdlib.h> */ import "C" import ( "unsafe" " ...

  7. IntelliJ IDEA 2017.3尚硅谷-----创建动态的 Java Web

  8. Mybaits(11)延迟加载

    一.概述 1.概念 就是在需要用到数据时才去进行加载,不需要用的数据就不加载数据.延迟加载也称为懒加载. 2.优缺点 优点:先从单表查询,需要时再从关联表去关联查询,大大提高数据库性能,因为查询单表要 ...

  9. [lua]紫猫lua教程-命令宝典-L1-01-07. table表

    L1[table]01. table表的定义与赋值 小知识:声明表的例子 xx={}--创建一个空表xx --给这表的元素赋值 test="a" xx[test]="a& ...

  10. 自动化脚本-配置LVS(DR模式)

    一,获取所需配置的主机IP cat get_ip.sh #!/bin/bash #将获得到的IP地址写进IP.txt >ip.txt #将原有的hosts信息清除 >/root/.ssh/ ...