-
Notifications
You must be signed in to change notification settings - Fork 3
/
2449.cpp
31 lines (31 loc) · 1000 Bytes
/
2449.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
class Solution {
public:
long long makeSimilar(vector<int>& nums, vector<int>& target) {
sort(nums.begin(), nums.end());
sort(target.begin(), target.end());
vector<int> numsOdd;
vector<int> numsEven;
vector<int> targetOdd;
vector<int> targetEven;
for (auto& num : nums) {
if (num & 1) numsOdd.push_back(num);
else numsEven.push_back(num);
}
for (auto& num : target) {
if (num & 1) targetOdd.push_back(num);
else targetEven.push_back(num);
}
long long res = 0;
int n = numsOdd.size();
for (int i = 0; i < n; ++i) {
if (numsOdd[i] < targetOdd[i]) continue;
res += (numsOdd[i] - targetOdd[i]) / 2;
}
n = numsEven.size();
for (int i = 0; i < n; ++i) {
if (numsEven[i] < targetEven[i]) continue;
res += (numsEven[i] - targetEven[i]) / 2;
}
return res;
}
};