You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.

Output the minimum possible value of error after k1 operations on array A and k2operations on array B have been performed.

Input

The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively.

Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A.

Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.

Output

Output a single integer — the minimum possible value of  after doing exactly k1 operations on array A and exactly k2 operations on array B.

Examples

Input
2 0 0
1 2
2 3
Output
2
Input
2 1 0
1 2
2 2
Output
0
Input
2 5 7
3 4
14 4
Output
1

Note

In the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2.

In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.

In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.

【题目概述】

给你两个数字序列a,b,每个序列长度都为n,然后E=∑(a[i]-b[i])^2。现在你可以改变a,b序列中的元素k1次和k2次,每次可以使一个元素加一或者减一。使得改变结束之后E的值最小

【思路阐述】

每一次的操作都会使差值变化,+1或-1,目标是使差值离0越近越好,那么当存在有大于0的差值时,就让改差值减一,如果当所有差值为0的时,就让其中一个(就第一个)差值加一。

 #include<bits/stdc++.h>
using namespace std;
struct node{
int a;
int b;
int dif;
}num[]; bool cmp(node a,node b) {
return a.dif > b.dif;
} int main() {
int n,k1,k2;
while(~scanf("%d %d %d",&n,&k1,&k2)) {
for(int i = ; i < n; i++) scanf("%d",&num[i].a);
for(int i = ; i < n; i++) {
scanf("%d",&num[i].b);
num[i].dif = abs(num[i].a - num[i].b);
}
sort(num,num+n,cmp);
int op = k1 + k2;
int count = ;
for(int i = ; i < op; i++) {
if(num[].dif == ) num[].dif++;
else num[].dif--;
count++;
sort(num,num+n,cmp);
}
long long int ans = ;
for(int i = ; i < n; i++) {
ans += pow(num[i].dif,);
} cout<<ans<<endl;
}
return ;
}

Minimize the error CodeForces - 960B的更多相关文章

  1. 【codeforces】【比赛题解】#960 CF Round #474 (Div. 1 + Div. 2, combined)

    终于打了一场CF,不知道为什么我会去打00:05的CF比赛…… 不管怎么样,这次打的很好!拿到了Div. 2选手中的第一名,成功上紫! 以后还要再接再厉! [A]Check the string 题意 ...

  2. 19 Error handling and Go go语言错误处理

    Error handling and Go go语言错误处理 12 July 2011 Introduction If you have written any Go code you have pr ...

  3. # ML学习小笔记—Where does the error come from?

    关于本课程的相关资料http://speech.ee.ntu.edu.tw/~tlkagk/courses_ML17.html 错误来自哪里? error due to "bias" ...

  4. 李宏毅机器学习课程---3、Where does the error come from

    李宏毅机器学习课程---3.Where does the error come from 一.总结 一句话总结:机器学习的模型中error的来源是什么 bias:比如打靶,你的瞄准点离准心的偏移 va ...

  5. (转) Summary of NIPS 2016

    转自:http://blog.evjang.com/2017/01/nips2016.html           Eric Jang Technology, A.I., Careers       ...

  6. Propagation of Visual Entity Properties Under Bandwidth Constraints

    1. Introduction The Saga of Ryzom is a persistent massively-multiplayer online game (MMORPG) release ...

  7. Deep Learning in a Nutshell: History and Training

    Deep Learning in a Nutshell: History and Training This series of blog posts aims to provide an intui ...

  8. (转)The AlphaGo Replication Wiki

    The AlphaGo Replication Wiki 摘自:https://github.com/Rochester-NRT/RocAlphaGo/wiki/01.-Home Contents : ...

  9. (转)The Road to TensorFlow

    Stephen Smith's Blog All things Sage 300… The Road to TensorFlow – Part 7: Finally Some Code leave a ...

随机推荐

  1. python xml.dom模块解析xml

    1. 什么是xml?有何特征? xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 例子:del.xml <?xml version=&q ...

  2. 使用Git进行代码版本管理及协同工作

    Git简介: git是一种较为先进的代码版本管理及协同工作平台,采用分布式文件块存储: 1.  分布式: 代码保存在所有协同成员的计算机上,网速较差时依然可用:而传统的集中式代码版本管理系统则较难脱离 ...

  3. Python系列之 - 面向对象(1)

    python是一门面向对象的编程语言,python中的一切均是对象. 有对象就提到类,对象和类就像是儿子和老子的关系,是不可分的一对. 什么是类     类就是具有一些共同特性的事物的统称.好比人类, ...

  4. 正则-匹配IP地址

    >>> re.search(r'[aeiouAEIOU]','I love FishC.com!') 中括号里面的任意一个字符匹配成功就会返回数值 <_sre.SRE_Matc ...

  5. Linux提示字符设置

    当我们登陆linux后,显示的提示字符究竟是什么意思呢?又可不可以设置呢. 首先来看看默认的显示: 普通用户: [fuwh@localhost ~]$ root用户: [root@localhost ...

  6. [BZOJ 2144]跳跳棋

    Description 跳跳棋是在一条数轴上进行的.棋子只能摆在整点上.每个点不能摆超过一个棋子.我们用跳跳棋来做一个简单的游戏:棋盘上有3颗棋子,分别在a,b,c这三个位置.我们要通过最少的跳动把他 ...

  7. sdut 2878 圆圈

    [ 题目描述]现在有一个圆圈, 顺时针标号分别从 0 到 n-1, 每次等概率顺时针走一步或者逆时针走一步,即如果你在 i 号点,你有 1/2 概率走到((i-1)mod n)号点,1/2 概率走到( ...

  8. 矩阵树Matrix-Tree定理与行列式

    简单入门一下矩阵树Matrix-Tree定理.(本篇目不涉及矩阵树相关证明) 一些定义与定理 对于一个无向图 G ,它的生成树个数等于其基尔霍夫Kirchhoff矩阵任何一个N-1阶主子式的行列式的绝 ...

  9. HDU2222 自动机(学习中)

    题目大意: 给你很多个单词,然后给你一篇文章,问给出的单词在文章中出现的次数. 解题思路: AC自动机入门题.需要注意的就是可能有重复单词 代码如下: #include<iostream> ...

  10. hdu 5480(前缀和)

    题意:如果一个点,则这点的横竖皆被占领,询问矩阵是否全被占领. 思路:将被占领的x,y标记为1,用x表示1 - i的和 如果x轴的差为 x2 - x1 + 1则表示全被占领,y轴同理 #include ...