CF898E.Squares and not squares
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ann and Borya have n piles with candies and n is even number. There are a__i candies in pile with number i.
Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is new and doesn't belong to any other pile) or remove one candy (if there is at least one candy in this pile).
Find out minimal number of moves that is required to make exactly n / 2 piles contain number of candies that is a square of some integer and exactly n / 2 piles contain number of candies that is not a square of any integer.
安和鲍里亚有 n 堆糖果,其中 n 是偶数。第 i 堆中有 ai 颗糖果。
安喜欢那些是某个整数的平方的数,而鲍里亚不喜欢任何整数的平方数。在一次操作中,两人可以选择某一堆糖果,向其中添加一颗糖果(这颗糖果是新加入的,不属于其他任何一堆),或者移除一颗糖果(前提是该堆中至少有一颗糖果)。
请找出最少需要多少次操作,使得恰好有 n/2 堆糖果的数量为某个整数的平方,另外恰好有 n/2 堆糖果的数量不是任何整数的平方。
输入格式
First line contains one even integer n (2 ≤ n ≤ 200 000) — number of piles with candies.
Second line contains sequence of integers _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 109) — amounts of candies in each pile.
第一行包含一个偶数整数 n(2≤n≤200000)—— 表示糖果堆的数量。
第二行包含一个整数序列 a1,a2,...,an(0≤ai≤109)—— 表示每堆糖果的数量。
输出格式
Output minimal number of steps required to make exactly n / 2 piles contain number of candies that is a square of some integer and exactly n / 2 piles contain number of candies that is not a square of any integer. If condition is already satisfied output 0.
输出使恰好 n/2 堆糖果的数量为某个整数的平方、且恰好 n/2 堆糖果的数量不是任何整数的平方所需的最少操作步数。如果条件已满足,则输出 0。
输入输出样例
输入#1
4 12 14 30 4
输出#1
2
输入#2
6 0 0 0 0 0 0
输出#2
6
输入#3
6 120 110 23 34 25 45
输出#3
3
输入#4
10 121 56 78 81 45 100 1 0 54 78
输出#4
0
说明/提示
In first example you can satisfy condition in two moves. During each move you should add one candy to second pile. After it size of second pile becomes 16. After that Borya and Ann will have two piles with number of candies which is a square of integer (second and fourth pile) and two piles with number of candies which is not a square of any integer (first and third pile).
In second example you should add two candies to any three piles.
在第一个例子中,你可以在两步内满足条件。每步操作中,你都应向第二堆糖果添加一颗糖果。操作完成后,第二堆糖果的数量变为 16。此后,Borya 和 Ann 将拥有两堆糖果数量为某个整数的平方(第二堆和第四堆),以及两堆糖果数量不是任何整数的平方(第一堆和第三堆)。
在第二个例子中,你应向任意三堆糖果各添加两颗糖果。
输入解题思路,AI测评打分。不知道怎么写?