Codeforces Round #622 (Div. 2) 1313 C1
C1. Skyscrapers (easy version)
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
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.
枚举最大值点像两侧延申(暴力)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e5 + 10;
ll a[N];
ll temp[N];
ll res[N];
int n;
void solve()
{
ll ans = 0;
for (int i = 1; i <= n; ++i)
{
ll m = 0;
m += a[i];
ll p = a[i];
temp[i] = p;
int l = i - 1;
while (l >= 1)
p = min(p, a[l]), temp[l] = p, m += p, l--;
int r = i + 1;
p = a[i];
while (r <= n)
p = min(p, a[r]), temp[r] = p, m += p, r++;
if (m > ans)
{
ans = m;
for (int i = 1; i <= n; ++i)
res[i] = temp[i];
}
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
solve();
for (int i = 1; i <= n; ++i)
cout << res[i] << ' ';
}
Codeforces Round #622 (Div. 2) 1313 C1的更多相关文章
- Codeforces Round #622 (Div. 2) 1313 B Different Rules
B. Different Rules Nikolay has only recently started in competitive programming, but already qualifi ...
- Codeforces Round #622 (Div. 2) 1313 A
Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)
Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)
Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...
- Codeforces Round #622(Div 2) C1. Skyscrapers (easy version)
题目链接: C1. Skyscrapers (easy version) 题目描述: 有一行数,使得整个序列满足 先递增在递减(或者只递增,或者只递减) ,每个位置上的数可以改变,但是最大不能超过原来 ...
- Codeforces Round #622 (Div. 2) C1. Skyscrapers (easy version)(简单版本暴力)
This is an easier version of the problem. In this version n≤1000n≤1000 The outskirts of the capital ...
- Codeforces Round #622 (Div. 2).C2 - Skyscrapers (hard version)
第二次写题解,请多多指教! http://codeforces.com/contest/1313/problem/C2 题目链接 不同于简单版本的暴力法,这个数据范围扩充到了五十万.所以考虑用单调栈的 ...
随机推荐
- Java第二十五天,多线程之等待唤醒机制
当线程被创建并且被启动之后,它既不是一启动就进入了执行状态,也不是一直处于执行状态,而是具有以下多种状态: 这六种状态之间的转换关系如下: 1.等待唤醒机制 注意: (1)两个线程之间必须用同步代码块 ...
- postman 工具接口测试
一.get:请求多个参数时,需要用&连接 eg:http://api.***.cn/api/user/stu_info?stu_name=小黑&set=女 eg:接口请求参数放在b ...
- 从零搭建一个SpringCloud项目之Config(五)
配置中心 一.配置中心服务端 新建项目study-config-server 引入依赖 <dependency> <groupId>org.springframework.cl ...
- java 中类为啥要序列化
java里为什么要序列化?http://zhidao.baidu.com/link?url=7_wAQ8eAl28vcJPE5OKM5Y0Bo4aINNQokHhRmI9XPszEoTO5QF-gNb ...
- Tomcat5启动流程与配置详解
标签:配置 tomcat 休闲 职场 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://zhangjunhd.blog.51cto. ...
- 【乱码问题】IDEA控制台使用了GBK字符集
什么Tomcat乱码设置IDEA的初始编码,瞎搞 终于在这个帖子看到了真相 https://blog.csdn.net/weixin_42617398/article/details/81806438 ...
- work of 1/5/2016
part 组员 今日工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 UI页面切换,词本显示下滑条 6 继续下滑条等增删补 ...
- C - Trailing Zeroes (III) 二分
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...
- CodeForces - 913C (贪心)
点完菜,他们发现好像觉得少了点什么? 想想马上就要回老家了某不愿透露姓名的林姓学长再次却陷入了沉思......... 他默默的去前台打算点几瓶二锅头. 他发现菜单上有n 种不同毫升的酒. 第 i 种有 ...
- G - GCD and LCM 杭电
Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, sa ...