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.

枚举最大值点像两侧延申(暴力)

  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int N = 5e5 + 10;
  5. ll a[N];
  6. ll temp[N];
  7. ll res[N];
  8. int n;
  9. void solve()
  10. {
  11. ll ans = 0;
  12. for (int i = 1; i <= n; ++i)
  13. {
  14. ll m = 0;
  15. m += a[i];
  16. ll p = a[i];
  17. temp[i] = p;
  18. int l = i - 1;
  19. while (l >= 1)
  20. p = min(p, a[l]), temp[l] = p, m += p, l--;
  21. int r = i + 1;
  22. p = a[i];
  23. while (r <= n)
  24. p = min(p, a[r]), temp[r] = p, m += p, r++;
  25. if (m > ans)
  26. {
  27. ans = m;
  28. for (int i = 1; i <= n; ++i)
  29. res[i] = temp[i];
  30. }
  31. }
  32. }
  33. int main()
  34. {
  35. cin >> n;
  36. for (int i = 1; i <= n; ++i)
  37. cin >> a[i];
  38. solve();
  39. for (int i = 1; i <= n; ++i)
  40. cout << res[i] << ' ';
  41. }

Codeforces Round #622 (Div. 2) 1313 C1的更多相关文章

  1. Codeforces Round #622 (Div. 2) 1313 B Different Rules

    B. Different Rules Nikolay has only recently started in competitive programming, but already qualifi ...

  2. 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 ...

  3. Codeforces Round #672 (Div. 2) A - C1题解

    [Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...

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

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

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

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

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

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

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

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

  8. 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 ...

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

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

随机推荐

  1. sqlchemy的外键及其约束条件

    外键创建 使用sqlalchemy创建外键非常简单.在表中增加一个字段,制定这个字段外键的是哪个表的哪个字段就可以了. 从表中外键定义的字段必须和主键字段类型保持一致. 实例代码: import mo ...

  2. 程序员的 Ubuntu 19.10 配置与优化指南

    原文地址:程序员的 Ubuntu 19.10 配置与优化指南 0x00 环境 CPU: Intel Core i9-9900k GPU: GeForce RTX 2070 SUPER RAM: DDR ...

  3. 数据结构和算法(Golang实现)(13)常见数据结构-可变长数组

    可变长数组 因为数组大小是固定的,当数据元素特别多时,固定的数组无法储存这么多的值,所以可变长数组出现了,这也是一种数据结构.在Golang语言中,可变长数组被内置在语言里面:切片slice. sli ...

  4. Odoo 查看 模块app 对应的 源码 相关依赖模块信息

    安装好app后再路径上 加上debug ,在查看 app 信息 如下 http://127.0.0.1:8069/web?debug#id=138&view_type=form&mod ...

  5. Loading纯JS

    function showLoading() { document.getElementById("over").style.display = "block" ...

  6. AJ学IOS(10)UI之_NSTimer_ios计时器

    AJ分享,必须精品 先看效果 代码 #import "NYViewController.h" @interface NYViewController () <UIAlertV ...

  7. 数论-质因数(gcd) UVa 10791 - Minimum Sum LCM

    https://vjudge.net/problem/UVA-10791/origin 以上为题目来源Google翻译得到的题意: 一组整数的LCM(最小公倍数)定义为最小数,即 该集合的所有整数的倍 ...

  8. 使用原生js实现选项卡功能实例教程

    选项卡是前端常见的基本功能,它是用多个标签页来区分不同内容,通过选择标签快速切换内容.学习本教程之前,读者需要具备html和css技能,同时需要有简单的javascript基础. 先来完成html部分 ...

  9. 利用numpy实现多维数组操作图片

    1.上次介绍了一点点numpy的操作,今天我们来介绍它如何用多维数组操作图片,这之前我们要了解一下色彩是由blue ,green ,red 三种颜色混合而成,0:表示黑色 ,127:灰色 ,255:白 ...

  10. jQuery+ajax实现滚动到页面底部自动加载图文列表效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...