大佬求调,阿里嘎多,thank you,思密达,70分,WA
查看原帖
大佬求调,阿里嘎多,thank you,思密达,70分,WA
1092522
I_am_wjr_I_AK_IOI楼主2024/7/10 09:03
#include<bits/stdc++.h>
#define LL long long  
using namespace std;
int n,k,h[1000010],w[1000010],m,ans,sss=1;
int cmp(int x,int y){
	return x<y;
}
int main()
{
	
	cin>>m>>n;
	for(int i=1;i<=m;i++){
		cin>>h[i];
	}
	
	for(int i=1;i<=n;i++){
		cin>>w[i];
	}
	sort(w+1,w+n+1,cmp);
	sort(h+1,h+m+1,cmp);
	h[0]=0;
	h[m+1]=1000000;
	for(int i=0;i<=m;i++){
		for(int j=sss;j<=n;j++){
			if((h[i]<=w[j])&&(w[j]<=h[i+1])){
				ans+=min((w[j]-h[i]),(h[i+1]-w[j]));
			}
			if(h[i+1]<w[j]){
				sss=j;
				break;
			}
		}
	}
	cout<<ans;
	return 0;	
}
2024/7/10 09:03
加载中...