CF960B.Minimize the error

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 _k_1 operations on array A and exactly _k_2 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 _k_1 operations on array A and _k_2 operations on array B have been performed.

给你两个长度均为 nn 的数组 AA 和 BB。这两个数组之间的误差 EE 定义为:

你必须恰好对数组 AA 执行 k1k_1 次操作,且恰好对数组 BB 执行 k2k_2 次操作。每次操作中,你需选择该数组中的一个元素,并将其加 11 或减 11。

输出在对数组 AA 执行 k1k_1 次操作、对数组 BB 执行 k2k_2 次操作后,所能达到的误差 EE 的最小可能值。

输入格式

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

Second line contains n space separated integers _a_1, _a_2, ..., a__n ( - 106 ≤ a__i ≤ 106) — array A.

Third line contains n space separated integers _b_1, _b_2, ..., b__n ( - 106 ≤ b__i ≤ 106)— array B.

第一行包含三个用空格分隔的整数 nn(1 ≤ n ≤ 1031 \leq n \leq 10^3)、k1k_1 和 k2k_2(0 ≤ k1 + k2 ≤ 1030 \leq k_1 + k_2 \leq 10^3,且 k1k_1 与 k2k_2 均为非负整数)——分别表示数组的大小,以及需在数组 AA 和 BB 上执行的操作次数。

第二行包含 nn 个用空格分隔的整数 a1, a2, ..., ana_1, a_2, ..., a_n(−106 ≤ ai ≤ 106-10^6 \leq a_i \leq 10^6)——数组 AA。

第三行包含 nn 个用空格分隔的整数 b1, b2, ..., bnb_1, b_2, ..., b_n(−106 ≤ bi ≤ 106-10^6 \leq b_i \leq 10^6)——数组 BB。

输出格式

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

输出一个整数——在对数组 AA 恰好执行 k1k_1 次操作、对数组 BB 恰好执行 k2k_2 次操作后, 的最小可能值。

输入输出样例

  • 输入#1

    2 0 0
    1 2
    2 3

    输出#1

    2
  • 输入#2

    2 1 0
    1 2
    2 2

    输出#2

    0
  • 输入#3

    2 5 7
    3 4
    14 4

    输出#3

    1

说明/提示

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 8 using 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.

在第一个样例中,我们无法对数组 AA 或 BB 执行任何操作。因此,最小可能的误差为 E=(1−2)2+(2−3)2=2E = (1 - 2)^2 + (2 - 3)^2 = 2。

在第二个样例中,我们必须恰好对数组 AA 执行一次操作。为使误差最小化,我们将 AA 的第一个元素加 11。此时,A=[2, 2]A = [2,\ 2]。误差变为 E=(2−2)2+(2−2)2=0E = (2 - 2)^2 + (2 - 2)^2 = 0。这是可达到的最小误差。

在第三个样例中,我们可以将 AA 的第一个元素增加至 88,用尽全部 55 次操作;同时,可将 BB 的第一个元素使用 77 次操作中的 66 次减少至 88。此时,A=[8, 4]A = [8,\ 4],B=[8, 4]B = [8,\ 4],误差为 E=(8−8)2+(4−4)2=0E = (8 - 8)^2 + (4 - 4)^2 = 0,但我们对数组 BB 还剩余 11 次操作。利用该剩余操作将 BB 的第二个元素增至 55,得到 B=[8, 5]B = [8,\ 5],此时误差为 E=(8−8)2+(4−5)2=1E = (8 - 8)^2 + (4 - 5)^2 = 1。

输入解题思路,AI测评打分。不知道怎么写?

首页