This is an easier version of the problem. In this version n≤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 n plots along the highway and is preparing to build n 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 1 to n. Then if the skyscraper on the i-th plot has ai floors, it must hold that ai is at most mi (1≤ai≤mi). Also there mustn’t be integers j and k such that j<iai<ak. Plots j and k are not required to be adjacent to i.

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 n (1≤n≤1000) — the number of plots.

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

Output
Print n integers ai — 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
inputCopy
5
1 2 3 2 1
outputCopy
1 2 3 2 1
inputCopy
3
10 6 8
outputCopy
10 6 6
Note
In the first example, you can build all skyscrapers with the highest possible height.

In the second test example, you cannot give the maximum height to all skyscrapers as this violates the design code restriction. The answer [10,6,6] is optimal. Note that the answer of [6,6,8] also satisfies all restrictions, but is not optimal.
思路:对于每一个i,i左边的位置定义为j,i右边的位置定义为k。要使得aj>ai<ak。我们可以画一下,要满足这一条件,就会使得这一串为一个“波”形。由于只有1000的数据量,直接暴力就可以了。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=1e3+100;
int a[maxx],b[maxx],c[maxx];
int n;int main()
{scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]),c[i]=a[i];ll _max=0;for(int k=1;k<=n;k++){int pos=k;for(int i=pos-1;i>=1;i--) if(a[i]>a[i+1]) a[i]=a[i+1];for(int i=pos+1;i<=n;i++) if(a[i]>a[i-1]) a[i]=a[i-1];ll sum=0;for(int i=1;i<=n;i++) sum+=(ll)a[i];if(sum>_max){_max=sum;for(int i=1;i<=n;i++) b[i]=a[i];}for(int i=1;i<=n;i++) a[i]=c[i];}for(int i=1;i<=n;i++) cout<<b[i]<<" ";cout<<endl;return 0;
}

努力加油a啊,(o)/~

Skyscrapers (easy version)CodeForces - 1313C1(暴力)相关推荐

  1. [codeforces 1313C1] Skyscrapers (easy version) 问的是谷,答的是峰

    Codeforces Round #622 (Div. 2)   比赛人数5752 [codeforces 1313C1] Skyscrapers (easy version)   问的是谷,答的是峰 ...

  2. Skyscrapers (hard version) CodeForces - 1313C2(单调栈)

    This is a harder version of the problem. In this version n≤500000 The outskirts of the capital are b ...

  3. Too Many Segments (easy version) CodeForces - 1249D1(贪心+差分)

    题意 给多组线段,而每一个点的覆盖次数不超过K,每次可去除一个线段,问最少去多少线段以及线段的位置. The only difference between easy and hard version ...

  4. 智乃的树旋转(easy version)(思维+暴力)

    题目链接 https://ac.nowcoder.com/acm/contest/23478/G 题面 思路 因为题目中保证了一定会存在操作数量为1的情况,那么我们仔细读题,注意这么一句话智乃最近学习 ...

  5. Social Network (easy version)

    Social Network (easy version) CodeForces 1234B1 这是一道我曾经训练时做过的一道题,为了应对上面的要求指标我不得不把它掏了出来(doge),这道题还是有点 ...

  6. CodeForces - 1234B1 Social Network (easy version)

    CodeForces - 1234B1 Social Network (easy version) 题目: The only difference between easy and hard vers ...

  7. CodeForces - 1543D1 RPD and Rap Sheet (Easy Version)(异或+交互)

    题目链接:点击查看 题目大意:交互题猜密码,设原密码为 xxx,猜的密码为 yyy,如果没猜到,密码会自适应变成 zzz,满足 x⊕z=yx \oplus z=yx⊕z=y ,最多猜 nnn 次 题目 ...

  8. Codeforces Round #579 (Div. 3) F1. Complete the Projects (easy version) 排序 + 贪心

    传送门 文章目录 题意: 思路: 题意: 思路: 比较直观的想法就是对于bi≥0b_i\ge0bi​≥0的项目,我们将aia_iai​从小到大排序,让后依次加bib_ibi​,如果有取不到的,显然就无 ...

  9. Codeforces Round #828 (Div. 3) E1. Divisible Numbers (easy version) 解题报告

    原题链接: Problem - E1 - Codeforces 题目描述: This is an easy version of the problem. The only difference be ...

最新文章

  1. 小甲鱼python003答案_小甲鱼:Python学习笔记003_函数
  2. 「谷歌大脑」提出通过对长序列进行摘要提取,AI可自动生成「维基百科」
  3. [原]Oracle删除大表并回收空间的过程
  4. STL Priority_Queue
  5. html页面vertical,vertical.html
  6. 文巾解题 2. 两数相加
  7. 数据结构与算法,每日一道
  8. swift自行车品牌介绍_品牌101:简介
  9. 第一阶段冲刺 第三天
  10. 博客园项目开发中的难点
  11. 从未停止!OpenGL的版本历史和发展
  12. django2连接mysql_Django2.2 连接mySQL数据库
  13. 部署FIM 2010 R2——7验证不同林之间相同用户名密码同步
  14. libiconv移植
  15. 一个泛型句柄类--C++模板和泛型编程--c++ primer
  16. Android使用惠普打印机,USB直连静默打印
  17. 让Win7系统屏幕来个大翻转
  18. matlab怎么启动一个图形窗,Matlab在一个图形窗口里画多个图形的操作教程
  19. p1468 Party Lamps
  20. wifi p2p 调试

热门文章

  1. 微信小程序登录页php后台,微信小程序:微信登陆(ThinkPHP作后台)
  2. JTAG、JLINK、ULINK、ST-LINK的联系和区别
  3. node.js知识点总结
  4. mysql 多列合并为一列_多列数据合并一列,还在用数据透视就out了,用=号只要三步完成...
  5. Qt的json对象不具备类似指针、引用的行为导致的更新不成功问题解决
  6. Android开发之EditText输入框限制输入数字和字母的实现方式
  7. Android通过WebView在线打开PDF文件(文中提供源码下载)
  8. 7.33oracle安装不了,在RedHat7.0下安装Oracle的经历
  9. HDU6184【Counting Stars】(三元环计数)
  10. Elasticsearch索引备份与清理