CF1419D1.Sage's Birthday (easy version)
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the easy version of the problem. The difference between the versions is that in the easy version all prices ai are different. You can make hacks if and only if you solved both versions of the problem.
Today is Sage's birthday, and she will go shopping to buy ice spheres. All n ice spheres are placed in a row and they are numbered from 1 to n from left to right. Each ice sphere has a positive integer price. In this version all prices are different.
An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.
You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered.
这是该问题的简单版本。两个版本的区别在于:在简单版本中,所有价格 ai 均互不相同。仅当您同时解决了该问题的两个版本时,才允许进行 hack。
今天是 Sage 的生日,她将去商店购买冰球。全部 n 个冰球排成一行,从左到右依次编号为 1 到 n。每个冰球的价格均为正整数;在本版本中,所有价格互不相同。
若一个冰球的价格严格小于其两侧相邻冰球(即紧邻左侧与紧邻右侧的冰球)的价格,则称该冰球为“廉价冰球”。最左侧与最右侧的冰球不可能是廉价冰球。Sage 将选出所有廉价冰球,并仅购买这些冰球。
您可在 Sage 到店前先行前往商店,并按任意顺序重新排列这些冰球。请找出 Sage 最多能购买多少个冰球,并给出一种达到该最大值的冰球重排方案。
输入格式
The first line contains a single integer n (1≤n≤105) — the number of ice spheres in the shop.
The second line contains n different integers a1,a2,…,an (1≤ai≤109) — the prices of ice spheres.
第一行包含一个整数 n (1≤n≤105) —— 商店中冰球的数量。
第二行包含 n 个互不相同的整数 a1,a2,…,an (1≤ai≤109) —— 冰球的价格。
输出格式
In the first line print the maximum number of ice spheres that Sage can buy.
In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them.
第一行输出 Sage 最多能购买的冰球数量。
第二行按最优顺序输出冰球的价格。如果存在多个正确答案,输出任意一个即可。
输入输出样例
输入#1
5 1 2 3 4 5
输出#1
2 3 1 4 2 5
说明/提示
In the example it's not possible to place ice spheres in any order so that Sage would buy 3 of them. If the ice spheres are placed like this (3,1,4,2,5), then Sage will buy two spheres: one for 1 and one for 2, because they are cheap.
在该示例中,无法以任何顺序摆放冰球,使得 Sage 购买其中 3 个。如果冰球按 (3,1,4,2,5) 的顺序摆放,则 Sage 将购买两个冰球:价格为 1 和 2 的那两个,因为它们比较便宜。
输入解题思路,AI测评打分。不知道怎么写?