CF1537C.Challenging Cliffs

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are a game designer and want to make an obstacle course. The player will walk from left to right. You have nn heights of mountains already selected and want to arrange them so that the absolute difference of the heights of the first and last mountains is as small as possible.

In addition, you want to make the game difficult, and since walking uphill or flat is harder than walking downhill, the difficulty of the level will be the number of mountains ii (1≤i<n1 \leq i \lt n) such that hi≤hi+1h_i \leq h_{i+1} where hih_i is the height of the ii-th mountain. You don't want to waste any of the mountains you modelled, so you have to use all of them.

From all the arrangements that minimize ∣h1−hn∣|h_1-h_n|, find one that is the most difficult. If there are multiple orders that satisfy these requirements, you may find any.

你是一名游戏设计师,打算设计一个障碍赛道。玩家将从左向右行走。你已预先选定了 nn 座山的高度,现在希望将它们进行排列,使得第一座山与最后一座山的高度之差的绝对值 ∣h1−hn∣|h_1 - h_n| 尽可能小。

此外,为了增加游戏难度,由于上坡或平路比下坡更难行走,关卡的难度定义为满足 hi≤hi+1h_i \leq h_{i+1} 的山的个数(其中 1≤i<n1 \leq i < n),即非严格递增相邻对的个数;这里 hih_i 表示第 ii 座山的高度。你不想浪费任何已建模的山,因此必须使用全部 nn 座山。

在所有使 ∣h1−hn∣|h_1 - h_n| 最小的排列中,找出一个难度最大的排列。若存在多个满足上述条件的排列,输出任意一个即可。

输入格式

The first line will contain a single integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases. Then tt test cases follow.

The first line of each test case contains a single integer nn (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5) — the number of mountains.

The second line of each test case contains nn integers h1,…,hnh_1,\ldots,h_n (1≤hi≤1091 \leq h_i \leq 10^9), where hih_i is the height of the ii-th mountain.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5),表示山峰的数量。

每个测试用例的第二行包含 nn 个整数 h1,…,hnh_1,\ldots,h_n(1≤hi≤1091 \leq h_i \leq 10^9),其中 hih_i 表示第 ii 座山峰的高度。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output nn integers — the given heights in an order that maximizes the difficulty score among all orders that minimize ∣h1−hn∣|h_1-h_n|.

If there are multiple orders that satisfy these requirements, you may output any.

对于每个测试用例,输出 nn 个整数——即给定的高度值,按某种顺序排列,使得在所有满足 ∣h1−hn∣|h_1-h_n| 最小的排列中,该排列的难度得分最大。

若存在多个满足上述要求的排列,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    4
    4 2 1 2
    2
    3 1

    输出#1

    2 4 1 2 
    1 3

说明/提示

In the first test case:

The player begins at height 22, next going up to height 44 increasing the difficulty by 11. After that he will go down to height 11 and the difficulty doesn't change because he is going downhill. Finally the player will go up to height 22 and the difficulty will increase by 11. The absolute difference between the starting height and the end height is equal to 00 and it's minimal. The difficulty is maximal.

In the second test case:

The player begins at height 11, next going up to height 33 increasing the difficulty by 11. The absolute difference between the starting height and the end height is equal to 22 and it's minimal as they are the only heights. The difficulty is maximal.

在第一个测试用例中:

玩家起始于高度 22,接着上升至高度 44,难度增加 11。随后,玩家下降至高度 11,由于是下坡,难度保持不变。最后,玩家上升至高度 22,难度再增加 11。起始高度与终点高度的绝对差值为 00,这是可能的最小值。此时难度达到最大。

在第二个测试用例中:

玩家起始于高度 11,接着上升至高度 33,难度增加 11。起始高度与终点高度的绝对差值为 22,由于仅有这两个高度,该差值已是最小可能值。此时难度达到最大。

输入解题思路,AI测评打分。不知道怎么写?

首页