Codeforces Round #622 (Div. 2) B、C

B. Different Rules
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the largest number of problems wins, the organizers came up with different rules.

Suppose in the first round participant A took x-th place and in the second round — y-th place. Then the total score of the participant A is sum x+y. The overall place of the participant A is the number of participants (including A) having their total score less than or equal to the total score of A. Note, that some participants may end up having a common overall place. It is also important to note, that in both the first and the second round there were no two participants tying at a common place. In other words, for every i from 1 to n exactly one participant took i-th place in first round and exactly one participant took i-th place in second round.

Right after the end of the Olympiad, Nikolay was informed that he got x-th place in first round and y-th place in the second round. Nikolay doesn’t know the results of other participants, yet he wonders what is the minimum and maximum place he can take, if we consider the most favorable and unfavorable outcome for him. Please help Nikolay to find the answer to this question.

Input
The first line contains an integer t (1≤t≤100) — the number of test cases to solve.

Each of the following t lines contains integers n, x, y (1≤n≤109, 1≤x,y≤n) — the number of participants in the olympiad, the place that Nikolay took in the first round and the place that Nikolay took in the second round.

Output
Print two integers — the minimum and maximum possible overall place Nikolay could take.

Examples
inputCopy
1
5 1 3
outputCopy
1 3
inputCopy
1
6 3 4
outputCopy
2 6
Note
Explanation for the first example:

Suppose there were 5 participants A-E. Let’s denote Nikolay as A. The the most favorable results for Nikolay could look as follows:

题意:给出选手A两场竞赛的排名x,y 问综合排名A最高的排名和最低的排名分别是多少 以x+y来计算

思路:在这里插入图片描述

#include <bits/stdc++.h>

using namespace std;

#define LL long long

const int N = 304 << 1;

int main()
{
    ios::sync_with_stdio(false);

    int t;cin >> t;

    while(t --)
    {
        LL n,x,y;

        cin >> n >> x >> y;

        cout << min(n,max(1LL,x + y + 1 - n)) << ' ' << min(n,x + y - 1) << '\n';
    }

    return 0;
}

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.

题意:给出n栋楼的高度 构建方案 要满足中间的到两边非严格降序
思路:按照题意模拟

#include <bits/stdc++.h>

using namespace std;

#define LL long long

const int N = 1005;

int h[N],a[N],ans[N];

int main()
{
    ios::sync_with_stdio(false);

    int n ;

    cin >> n ;

    for(int i = 1;i <= n;i ++)
        cin >> h[i];

    LL sum = 0;
    LL res = 0;

    for(int i = 1;i <= n;i ++)
    {
        sum = 0;

        memset(a,0,sizeof(a));

        a[i] = h[i];
        sum += h[i];

        for(int j = i - 1;j >= 1;j --)
        {
            a[j] = min(h[j],a[j + 1]);
            sum += a[j];
        }

        for(int j = i + 1;j <= n;j ++)
        {
            a[j] = min(h[j],a[j - 1]);
            sum += a[j];
        }

        if(sum > res)
        {
            res = sum;

            for(int i = 1;i <= n;i ++)
                ans[i] = a[i];
        }
    }

    for(int i = 1;i <= n;i ++)
        cout << ans[i] << ' ';

    cout << '\n';

    return 0;
}

C2
题意一样 数据范围变成5e5

考虑用单调栈维护 复杂度 O(n) 待补

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值