304710: CF898E. Squares and not squares
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Squares and not squares
题意翻译
Ann和Borya有n堆糖果并且n是偶数。第i堆糖果里有a[i]个糖果 Ann喜欢完全平方数但Borya不喜欢。每次操作可以在一堆糖果中加上或减少一个糖果。糖果数不可以是负数。 输出最小操作次数使得n堆糖果中有恰好n/2堆的糖果数是完全平方数题目描述
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.输入输出格式
输入格式
First line contains one even integer $ n $ ( $ 2<=n<=200000 $ ) — number of piles with candies. Second line contains sequence of integers $ a_{1},a_{2},...,a_{n} $ ( $ 0<=a_{i}<=10^{9} $ ) — amounts of candies in each pile.
输出格式
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.
输入输出样例
输入样例 #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