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 题目链接 不同于简单版本的暴力法,这个数据范围扩充到了五十万.所以考虑用单调栈的 ...
随机推荐
- 微信小程序页面跳转的三种方式总结
原文链接 https://blog.csdn.net/zgmu/article/details/72123329 首先我们了解到,小程序规定页面路径只能有五层,所以我们尽量避免多层级的页面跳转 页面跳 ...
- javascript 入门 select2
要说这select2,还真是我......,也不是难,反正就对不了!!! 我博客看了一下牛,愣是对不了,后来硬着头看着官方文档,终于出来了. 注意: 1.调用的jquery库一定要能用,网上很多不能用 ...
- 盘点一下Github上开源的编程面试/学习相关的仓库
转载自:JavaGuide 最近浏览 Github ,收藏了一些还算不错的 Java面试/学习相关的仓库,分享给大家,希望对你有帮助.我暂且按照目前的 Star 数量来排序. 本文由 SnailCli ...
- bootstrapTest
<!DOCTYPE html><html lang="zh-CN"> <head> <meta charset="utf-8&q ...
- coding++:都说新的Arraylist 扩容是(1.5倍+1) 看了1.8的源代码发现不是这么回事
都说新的Arraylist 扩容是(1.5倍+1) 看了1.8的源代码发现不是这么回事 就用下面这段代码在jdk的三个版本运行看了下效果: import java.lang.reflect.Fiel ...
- Restlet Client发送GET、POST等请求
插件下载 百度云盘 链接:https://pan.baidu.com/s/13R4s1UR5TONl2JnwTgtIYw 密码:rt02 插件安装 解压后,直接拖进浏览器中. 功能演示
- 测试需要用到的chrome调试
模拟慢网速 断开网络 F12后勾选上offline 请求304 后来发现是选中了该浏览其的Disable cache,去掉就好了.
- jmeter DB2数据库连接与操作
1.需要把数据库连接jar包拷贝到 jmeter lib目录下 先创建一个数据库连接配置元件 2.添加jdbc请求(我用的后置处理器) 3.可以通过beanshell 对结果集进行操作 beanshe ...
- scheduler_default_filters 详解
Filter scheduler 是 nova-scheduler 默认的调度器,调度过程分为两步: 通过过滤器(filter)选择满足条件的计算节点(运行 nova-compute) 通过权 ...
- Python大数据与机器学习之NumPy初体验
本文是Python大数据与机器学习系列文章中的第6篇,将介绍学习Python大数据与机器学习所必须的NumPy库. 通过本文系列文章您将能够学到的知识如下: 应用Python进行大数据与机器学习 应用 ...