A. Salem and Sticks
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Salem gave you nn sticks with integer positive lengths a1,a2,…,ana1,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 aa to bb is |a−b||a−b|, where |x||x| means the absolute value of xx.

A stick length aiai is called almost good for some integer tt if |ai−t|≤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 tt and the total cost of changing is minimum possible. The value of tt is not fixed in advance and you can choose it as any positive integer.

As an answer, print the value of tt and the minimum cost. If there are multiple optimal choices for tt, print any of them.

Input

The first line contains a single integer nn (1≤n≤10001≤n≤1000) — the number of sticks.

The second line contains nn integers aiai (1≤ai≤1001≤ai≤100) — the lengths of the sticks.

Output

Print the value of tt and the minimum possible cost. If there are multiple optimal choices for tt, print any of them.

Examples
input

Copy
3
10 1 4
output

Copy
3 7
input

Copy
5
1 1 2 2 3
output

Copy
2 0
Note

In the first example, we can change 11 into 22 and 1010 into 44 with cost |1−2|+|10−4|=1+6=7|1−2|+|10−4|=1+6=7 and the resulting lengths [2,4,4][2,4,4]are almost good for t=3t=3.

In the second example, the sticks lengths are already almost good for t=2t=2, so we don't have to do anything.

 #include <bits/stdc++.h>
#include <cstdio> using namespace std; int n;
int a[];
int sum=; int cal(int k){
int res=;
for(int i=;i<n;i++){
if(abs(a[i]-k)>){
res+=(abs(a[i]-k)-);
}
}
return res;
} int main()
{
int minn=;
int maxx=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
sum+=a[i];
minn=a[i]<minn?a[i]:minn;
maxx=a[i]>maxx?a[i]:maxx;
}
int r1=;
int cost=;
int now=;
for(int i=minn;i<=maxx;i++){
now=cal(i);
if(now<cost){
r1=i;
cost=now;
}
}
printf("%d %d\n",r1,cost);
/*
int r1=sum/n;
int r2=r1+1;
int _r1=cal(r1,a);
int _r2=cal(r2,a); if(_r1<_r2){
printf("%d %d\n",r1,_r1);
}else{
printf("%d %d\n",r2,_r2);
}
*/ return ;
}

codeforces_A. Salem and Sticks_数组/暴力的更多相关文章

  1. BZOJ 4556: [Tjoi2016&Heoi2016]字符串(后缀数组 + 二分答案 + 主席树 + ST表 or 后缀数组 + 暴力)

    题意 一个长为 \(n\) 的字符串 \(s\),和 \(m\) 个询问.每次询问有 \(4\) 个参数分别为 \(a,b,c,d\). 要你告诉它 \(s[a...b]\) 中的所有子串 和 \(s ...

  2. 【BZOJ-2251】外星联络 后缀数组 + 暴力

    2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 670  Solved: 392[Submit][ ...

  3. BZOJ 2754: [SCOI2012]喵星球上的点名 [后缀数组+暴力]

    2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1906  Solved: 839[Submit][St ...

  4. Codeforces Round #533 (Div. 2) A. Salem and Sticks(暴力)

    A. Salem and Sticks time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. [bzoj2251][2010Beijing Wc]外星联络——后缀数组+暴力求解

    Brief Description 找到 01 串中所有重复出现次数大于 1 的子串.并按字典序输出他们的出现次数. Algorithm Design 求出后缀数组之后,枚举每一个后缀,对于每个后缀从 ...

  6. [luoguP2336] [SCOI2012]喵星球上的点名(后缀数组 + 暴力)

    传送门 原本的想法是把所有的串不管是名字还是询问都连起来,记录一下询问串在sa数组中的位置 对于每个询问可以在sa数组中二分出左右边界,第一问用莫队,第二问差分乱搞. 结果发现我差分的思路想错了,先写 ...

  7. Codeforces Round #263 (Div. 1) C. Appleman and a Sheet of Paper 树状数组暴力更新

    C. Appleman and a Sheet of Paper   Appleman has a very big sheet of paper. This sheet has a form of ...

  8. 玲珑学院OJ 1023 - Magic boy Bi Luo with his excited math problem 树状数组暴力

    分析:a^b+2(a&b)=a+b  so->a^(-b)+2(a&(-b))=a-b 然后树状数组分类讨论即可 链接:http://www.ifrog.cc/acm/probl ...

  9. Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力

    E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Ale ...

随机推荐

  1. 终于有人把P2P、P2C、O2O、B2C、B2B、C2C 的区别讲透了!

    原文地址:https://www.cnblogs.com/sap-ronny/p/8149960.html P2P.P2C .O2O .B2C.B2B. C2C,每天看着这些常见又陌生的名词,如果有人 ...

  2. jmeter创建时间函数

    固定格式的年月日 ${__time(yyyyMMdd,)} 20151214 //返回年月日 ${__time(HHmmss,)} 092816 //返回时分秒 ${__time(yyyyMMdd-H ...

  3. webpack打包文件

    npm init -y//生成package.json npm install webpack webpack-cli --save-dev//安装webpack和webpack-cli根据入口文件. ...

  4. 主席树——树链上第k大spoj COT

    首先要求第k大就想到用主席树来处理 但是不能直接用树链剖分的dfs序来维护,因为一条链对应的dfs下标可能是断开的几段,无法用权值线段树来维护 那么久维护每个点到根节点的全值线段树,结点u的权值线段树 ...

  5. angular6、7 兼容ie9、10、11

    1. 找到 polyfill.ts 并打开注释 /** * This file includes polyfills needed by Angular and is loaded before th ...

  6. VS2017 提示警告 IDE0006

    MS的错误帮助:https://github.com/dotnet/roslyn/wiki/Diagnosing-Project-System-Build-Errors 看起来好复杂- 其实嘛- 检查 ...

  7. pyqt win32发送QQ消息

    标题应该改为:python+win32发送QQ消息,全程使用python套个pyqt壳. 其实代码来自: http://blog.csdn.net/suzyu12345/article/details ...

  8. typora画图

    https://steemit.com/utopian-io/@jubi/typora-typora-tutorial-exquisite-graph https://support.typora.i ...

  9. Redis 缓存失效和回收机制

    本文及后续文章,Redis版本均是v3.2.8 一.内存回收策略 maxmemory配置用于配置Redis存储数据时指定限制的内存大小.我们可以通过redis.conf配置或者使用CONFIG SET ...

  10. Schedule Problem spfa 差分约束

    题意:有n个任务,给出完成n个任务所需时间,以及一些任务安排.任务安排有四种: FAS a b:任务a需在任务b开始后完成. FAF a b:任务a需在任务b完成后完成. SAF a b:任务a需在任 ...