原题题目
代码实现(首刷自解)
class Solution {
public:int minAbsoluteSumDiff(vector<int>& nums1, vector<int>& nums2) {
vector<int> tmp(nums1);sort(tmp.begin(),tmp.end());int dif = 0;long ret = 0;for(int i=0;i<nums1.size();++i){
int maxnum = abs(nums2[i] - nums1[i]);auto pos = lower_bound(tmp.begin(),tmp.end(),nums2[i]) - tmp.begin();if(pos != tmp.size()) dif = max(dif,maxnum - abs(nums2[i] - tmp[pos]));if(--pos >= 0) dif = max(dif,maxnum - abs(nums2[i] - tmp[pos]));}for(int i=0;i<nums1.size();++i)ret = (ret + abs(nums2[i] - nums1[i]));return (ret - dif) % 1000000007;}
};