A. Salem and Sticks
题目描述
Salem gave you n n n sticks with integer positive lengths a1,a2,…,an a_1, a_2, \ldots, a_n a1,a2,…,an .
For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from a a a to b b b is ∣a−b∣ |a - b| ∣a−b∣ , where ∣x∣ |x| ∣x∣ means the absolute value of x x x .
A stick length ai a_i ai is called almost good for some integer t t t if ∣ai−t∣≤1 |a_i - t| \le 1 ∣ai−t∣≤1 .
Salem asks you to change the lengths of some sticks (possibly all or none), such that all sticks' lengths are almost good for some positive integer t t t and the total cost of changing is minimum possible. The value of t t t is not fixed in advance and you can choose it as any positive integer.
As an answer, print the value of t t t and the minimum cost. If there are multiple optimal choices for t t t , print any of them.
输入输出格式
输入格式:
The first line contains a single integer n n n ( 1≤n≤1000 1 \le n \le 1000 1≤n≤1000 ) — the number of sticks.
The second line contains n n n integers ai a_i ai ( 1≤ai≤100 1 \le a_i \le 100 1≤ai≤100 ) — the lengths of the sticks.
输出格式:
Print the value of t t t and the minimum possible cost. If there are multiple optimal choices for t t t , print any of them.
输入输出样例
输出样例#2: 2 0 直接暴力遍历就行了;
#include #include #include #include #include #include #include #include
#include #include #include #include #include #include #include #include
套路的DP?
设 dp[ i ][ j ]表示前i 个数余数为j的方案数;
#include #include #include #include #include #include #include #include
多源bfs就行了;
#include #include #include #include #include #include #include #include