-
Notifications
You must be signed in to change notification settings - Fork 1
/
B.cpp
65 lines (53 loc) · 1.15 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
#define inf 2e18
#define ll long long
ll a[1009], b[1009];
struct node {
ll i;
ll val;
} ara[1009];
bool cmp(node a, node b) {
return abs(a.val) > abs(b.val);
}
int main()
{
ll n, k1, k2;
cin >> n >> k1 >> k2;
for(ll i = 0; i < n; i++)
scanf("%lld", &a[i]);
for(ll i = 0; i < n; i++)
scanf("%lld", &b[i]);
ll mx = INT_MIN;
k1 += k2;
while(k1 > 0) {
mx = INT_MIN;
for(ll i = 0; i < n; i++)
mx = max(abs(a[i] - b[i]), mx);
if(mx == 0)
break;
for(ll i = 0; i < n; i++) {
if(mx == abs(a[i] - b[i] )) {
if(a[i] > b[i]) {
a[i] -= min(k1, 1LL);
}
else {
b[i] -= min(k1, 1LL);
}
k1 -= min(k1, 1LL);
}
}
/*if(test)
break;*/
}
ll sum = 0;
for(ll i = 0; i < n; i++) {
sum += (abs(a[i] - b[i]) * abs(a[i] - b[i]));
}
if(k1 < 0)
k1 = 0;
if(k1 % 2 != 0)
sum++;
cout << sum << endl;
return 0;
}