Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef int64_t Int;
- int main() {
- //freopen("input.txt", "rt", stdin);
- ios_base::sync_with_stdio(false);
- Int n, ka, kb; cin >> n >> ka >> kb;
- vector<Int> a(n), b(n);
- for (auto& it : a) cin >> it;
- for (auto& it : b) cin >> it;
- Int curr = 0;
- for (int i = 0; i < n; ++i) {
- curr += (a[i]-b[i])*(a[i]-b[i]);
- }
- for (int j = 0; j < ka; ++j) {
- Int min_i = -1;
- Int min_s = (Int)1e18L;
- bool is_inc = true;
- for (int i = 0; i < n; ++i) {
- { // try inc
- auto temp = a[i] + 1;
- auto next = curr + (temp - b[i]) * (temp-b[i]) - (a[i]-b[i])*(a[i]-b[i]);
- if (min_s > next) {
- min_i = i;
- is_inc = true;
- min_s = next;
- }
- }
- { // try dec
- auto temp = a[i] - 1;
- auto next = curr + (temp - b[i]) * (temp-b[i]) - (a[i]-b[i])*(a[i]-b[i]);
- if (min_s > next) {
- min_i = i;
- is_inc = false;
- min_s = next;
- }
- }
- }
- assert(min_i != -1);
- curr = min_s;
- if (is_inc) {
- a[min_i]++;
- } else {
- a[min_i]--;
- }
- }
- for (int j = 0; j < kb; ++j) {
- Int min_i = -1;
- Int min_s = (Int)1e18L;
- bool is_inc = true;
- for (int i = 0; i < n; ++i) {
- { // try inc
- auto temp = b[i] + 1;
- auto next = curr + (temp - a[i]) * (temp-a[i]) - (a[i]-b[i])*(a[i]-b[i]);
- if (min_s > next) {
- min_i = i;
- is_inc = true;
- min_s = next;
- }
- }
- { // try dec
- auto temp = b[i] - 1;
- auto next = curr + (temp - a[i]) * (temp-a[i]) - (a[i]-b[i])*(a[i]-b[i]);
- if (min_s > next) {
- min_i = i;
- is_inc = false;
- min_s = next;
- }
- }
- }
- assert(min_i != -1);
- curr = min_s;
- if (is_inc) {
- b[min_i]++;
- } else {
- b[min_i]--;
- }
- }
- cout << curr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement