最小的和

题目 最小的和

image-91f419af

思路分析

image-0174a044

我的这种分析貌似没用到多路归并 贪心加大根堆解决了

代码实现

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N=1e3+10;

int a[N],b[N];

priority_queue<LL> heap;

int n,k1,k2;

int main()

{

    cin>>n>>k1>>k2;

    for(int i=1;i<=n;i++)

        cin>>a[i];

    for(int i=1;i<=n;i++){

        cin>>b[i];

        heap.push(abs(a[i]-b[i]));

    }

    for(int i=1;i<=k1+k2;i++){

        auto temp=heap.top();

        heap.pop();

        heap.push(abs(temp-1));

    }

    LL res=0;

    while(!heap.empty()){

        auto temp=heap.top();

        heap.pop();

        res+=temp*temp;

    }

    cout<<res;

    return 0;

}

同类题型

视频讲解


⬅️ 推荐系统 🏠 00-刷题理模型 ➡️ 蚯蚓