Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- using ll = long long;
- public:
- long long makeSimilar(vector<int>& ns, vector<int>& tg) {
- vector<int> nse, nso;
- vector<int> tge, tgo;
- for (auto n: ns) if (n % 2) nso.push_back(n); else nse.push_back(n);
- for (auto n: tg) if (n % 2) tgo.push_back(n); else tge.push_back(n);
- sort(nso.begin(), nso.end());
- sort(nse.begin(), nse.end());
- sort(tgo.begin(), tgo.end());
- sort(tge.begin(), tge.end());
- ll ret = 0;
- for (int i = 0; i < nso.size(); ++i) {
- if (nso[i] < tgo[i])
- ret += (tgo[i] - nso[i]) / 2;
- }
- for (int i = 0; i < nse.size(); ++i) {
- if (nse[i] < tge[i])
- ret += (tge[i] - nse[i]) / 2;
- }
- return ret;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement