前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Codeforces Round #622 (Div. 2) 1313 C1

Codeforces Round #622 (Div. 2) 1313 C1

作者头像
风骨散人Chiam
发布2020-10-29 09:46:18
5630
发布2020-10-29 09:46:18
举报
文章被收录于专栏:CSDN旧文

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.

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

代码语言:javascript
复制
#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] << ' ';
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/02/23 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档