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. FreeMarker的用法

    freemark就是一个对静态页面上的标签进行动态解析.填充数据的一个框架. 语法(转:http://zhuyuehua.iteye.com/blog/1975251):  1. freemarker ...

  2. Java调用SQL脚本执行的方案

    在Java中调用SQL脚本的方式有多种,在这里只记录一种自己常用的方式,个人觉得挺实用方便的. 运用ScriptRunner这个类. import org.apache.ibatis.io.Resou ...

  3. JavaScript正则表达式学习笔记之一 - 理论基础

    自从年前得空写了两篇文章之后就开始忙了,这一忙就是2个月

  4. Plupload 上传控件使用指南

    本文转载至(感谢原作者分享):http://www.cnblogs.com/2050/p/3913184.html#plupload_doc2 我之前写过一篇文章<文件上传利器SWFUpload ...

  5. 使用Keras对交通标志进行分类

    # 使用Keras对交通标志进行分类 一.概述 本文主要记录的在使用Keras过程中,实现交通标志分类,数据集使用的是. 文本主要使用的环境为: Python3.5.2 Tensorflow 1.7 ...

  6. bzoj 2436: [Noi2011]Noi嘉年华

    Description NOI2011 在吉林大学开始啦!为了迎接来自全国各地最优秀的信息学选手,吉林大学决定举办两场盛大的 NOI 嘉年华活动,分在两个不同的地点举办.每个嘉年华可能包含很多个活动, ...

  7. 【NOIP2013TG】solution

    链接:https://www.luogu.org/problem/lists?name=&orderitem=pid&tag=83%2C30 D1T1:转圈游戏(circle) 题意: ...

  8. NOIWC颓废记

    NOIWC大概就干了3件事情:吃.睡.浪. 吃: 目测绍兴一中的饭比二中的好吃多了,每天都有挺多的肉菜,还有一些甜品,而且是自助,不错的,但是一个不好的是排队时间太长了,于是我这么珍惜时间急着回宿舍的 ...

  9. Mysq 索引优化

    MYSQL支持的索引类型 BTREE索引 特点: 通过引用以B+权的结构存储数据 能够加快数据的查询速度 更适合进行范围查找 应用: 全值匹配的查询 = 匹配最左前缀的查询 匹配列前缀查询 LIKE ...

  10. JavaScript实现简单的双向数据绑定

    什么是双向数据绑定 双向数据绑定简单来说就是UI视图(View)与数据(Model)相互绑定在一起,当数据改变之后相应的UI视图也同步改变.反之,当UI视图改变之后相应的数据也同步改变. 双向数据绑定 ...