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. 【转载】大白话Docker入门(二)

    原文:https://yq.aliyun.com/articles/63517?spm=a2c4e.11153940.blogcont63035.15.12011c3fddklk0 上篇的大白话Doc ...

  2. gojs常用API-画布定义

    持续更新中 基础画布定义API画布初始位置 initialContentAlignment: go.Spot.Center,画布位置,定义后就不能拖动画布了,画布位置交由gojs管理 contentA ...

  3. js原型链+继承 浅析

    名称:    prototype--原型对象    __proto__--属性 原型链与继承网上搜索定义,看起来挺绕的 .先说继承: 所有的对象实例都可以共享原型对象包含的属性和方法  例如一个实例A ...

  4. Python IDLE配置清屏快捷键(Ctrl+L)

    1.在Python\Lib\idlelib下,新建一个ClearWindow.py文件(没有时就新建),内容如下: """ Clear Window Extension ...

  5. foot

    码云链接:https://gitee.com/zyyyyyyyyyyy/codes/rcfdzmin4a82v975pl1ko47 效果图: 原网站截图: 源代码: <!DOCTYPE html ...

  6. Iterator 和 ListIterator 的不同点以及包含的方法

    当我们在对集合(List,Set)进行操作的时候,为了实现对集合中的数据进行遍历,经常使用到了Iterator(迭代器).使用迭代器,你不需要干涉其遍历的过程,只需要每次取出一个你想要的数据进行处理就 ...

  7. Joone

    JOONE 一.什么是JOONE? 1.Joone是一个免费的神经网络框架来创建,训练和测试人造神经网络.目标是为最热门的Java技术创造一个强大的环境,为热情和专业的用户.2.Joone由一个中央引 ...

  8. urllib-Proxy

    代理的使用: 首先,当我们正确爬取一个网页时,发现代码没有错误,可就是不能爬取网站.原因是有些网站设置了反爬取手段,就是知道你就是用python代码爬取该网站,设置了屏蔽.如果我们又想爬取该网站,便要 ...

  9. Codeforces 439E Devu and Birthday Celebration 容斥

    Devu and Birthday Celebration 我们发现不合法的整除因子在 m 的因子里面, 然后枚举m的因子暴力容斥, 或者用莫比乌斯系数容斥. #include<bits/std ...

  10. 2018-2019-3 网络对抗技术 20165235 Exp3 免杀原理与实践

    2018-2019-3 网络对抗技术 20165235 Exp3 免杀原理与实践 基础问题回答 杀软是如何检测出恶意代码的? 1.对某个文件的特征码进行分析,(特征码就是一类恶意文件中经常出现的一段代 ...