Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ff first
- #define ss second
- int main() {
- int t;
- cin>>t;
- while(t--){
- int n, m; cin >> n >> m;
- vector<int> a(n), b(n);
- for(int &x: a)
- cin >> x;
- map<int, pair<int, int>> diffs;
- map<int, int> c;
- for(int i = 0; i < n; i++){
- cin >> b[i];
- if(diffs.find(a[i] - b[i]) != diffs.end())
- {
- if(b[i] < (diffs[a[i] - b[i]]).ff)
- diffs[a[i] - b[i]] = {b[i], i};
- }
- else
- diffs[a[i] - b[i]] = {b[i], i};
- }
- vector<int> cc(m);
- for(int &x: cc){
- cin >> x;
- c[x]++;
- }
- int ans = 0;
- for(auto &[diff, temp] : diffs)
- {
- auto [bi, i] = temp;
- auto it = c.lower_bound(a[i]);
- while(it != c.end())
- {
- int cnt = (*it).second;
- int ci = (*it).first;
- int curr = (ci - bi)/(diff); ans += 2*curr*cnt;
- c.erase(it);
- c[ci - curr*diff] += cnt;
- it = c.lower_bound(a[i]);
- }
- }
- cout << ans << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment