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. 题解【洛谷P1314】[NOIP2011]聪明的质监员

    题面 题解 不难发现,\(W\)增大时,\(Y\)值会随之减小. 于是考虑二分\(W\). 如何\(\mathcal{O}(N)check?\) 每一次前缀和记录一下\(1-i\)之间\(w_i \g ...

  2. war文件—Web项目部署

    war文件是什么? Web存档(war)文件包含Web应用程序的所有内容.它减少了传输文件所需要的时间.  war文件的优点 节省时间:war文件将所有文件合并为一个单位. 所以在将文件从客户端传输到 ...

  3. Redis 要学的

    https://www.cnblogs.com/kismetv/p/8654978.html#t21 各个类型底层原理 慢查询 pipeline BitMaps 发布订阅 主从复制 psync psy ...

  4. C# LINQ GroupBy

    一.先准备要使用的类: 1.Person类: class Person { public string Name { set; get; } public int Age { set; get; } ...

  5. 基于.NET Core winform的录音、字幕软件HTWCore的技术总结

    HTWCore是一款基于.NET Core的winform客户端程序,可以用来处理各种会议,记录,讲座,讲课等等来源的音视频,运用语音识别.视频内容提取等技术整理成word文档.项目中运用了以下技术: ...

  6. C++类几种初始化的顺序

    首先给段代码: class A{ public: ; A():x(){cout<<"A(): x="<<x<<endl;} A(int a):x ...

  7. 剑指offer(leetcode 10.) 正则表达式匹配

    这题一年前就做过,当时刚开始刷leetcode,提交了几十次过不去,就放那没管了.今天剑指offer又遇到这题,终于做出来了,用的dp. class Solution { public: bool i ...

  8. vue + elementui表单重置 resetFields问题(无法重置表单)

    问题: elementui在重置表单时,无法使用this.$refs['formRefVal'].resetFields()清空表单数据; elementui 设置rules后没有效果 解决方法: 1 ...

  9. group by分组后对组内数据进行排序

    查询 每个班级英语成绩最高的前两名的记录 原文:https://www.cnblogs.com/hxfcodelife/p/10226934.html select a.Classid,a.Engli ...

  10. SparkSQL个人记录

    SparkSQL将RDD封装成一个DataFrame对象,这个对象类似于关系型数据库中的表. 一.SparkSQL入门 1.创建DataFrame 相当于数据库中的一张表,它是一个只读的表,不能在运算 ...