No need to complicate the things so much. Here's my code that passes all the cases (very similar approach but without multiset and what not, a bit cleaner):

#include <bits/stdc++.h>

using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b) {

return abs(a.first) > abs(b.first);

}

int main() {

long long sum = 0;

int n, x, y;

cin >> n >> x >> y;

vector<int> a(n), b(n);

vector< pair<int, int> > diff(n);

for (int i = 0; i < n; i++) cin >> a[i];

for (int i = 0; i < n; i++) cin >> b[i], diff[i] = {a[i] - b[i], i};