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. 题解-COCI-2015Norma

    Problem SPOJ-NORMA2 & bzoj3745 题意概要:给定一个正整数序列 \(\{a_i\}\),求 \[\sum_{i=1}^n\sum_{j=i}^n(j-i+1)\mi ...

  2. [insight] debug

    python: 1. print理解流程 print('xy1') print('xy2') 可以更好地跟踪函数的执行流程,分析代码 2. 用python库 import pdb; pdb.set_t ...

  3. Salesforce知识整理(一)之Lightning Web Component Tools

    目录 LWC知识整理(一) 工具 Salesforce CLI Visual Studio Code(VS Code) Developer Hub(Dev Hub) 开启Dev Hub 相关资料 茶余 ...

  4. R语言︱LDA主题模型——最优主题...

    R语言︱LDA主题模型——最优主题...:https://blog.csdn.net/sinat_26917383/article/details/51547298#comments

  5. shiro 错误登陆次数限制

    第一步:在spring-shiro.xml 中配置缓存管理器和认证匹配器 <!-- 缓存管理器 使用Ehcache实现 --><bean id="cacheManager& ...

  6. JQuery ajax 前后端传值介绍

    https://jingyan.baidu.com/album/ca41422f0bf08e1eae99ed04.html?picindex=5 现在我们话不多说,开始仔细讲解一下我们ajax内部传递 ...

  7. 结对-(first)

    代码地址 https://github.com/CountZ3/bank.git 代码思想 允许进程动态地申请资源, 系统在每次实施资源分配之前,先计算资源分配的安全性, 若此次资源分配安全(即资源分 ...

  8. java----SVN

    下载SVN server 安装服务器,注意需要配置端口和本地仓库 https://www.visualsvn.com/server/download/ 下载SVN client https://tor ...

  9. Android开发PreferenceActivity 用法的代码

    将开发过程中常用的一些内容做个收藏,下面资料是关于Android开发PreferenceActivity 用法的内容,希望对大伙有一些用处.public class Setting extends P ...

  10. selenium使用遇到的问题(selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.)

    1.安装pip3 install selenium 2.使用browser=webdriver.Chrome()时报错 :selenium.common.exceptions.WebDriverExc ...