求DALAO看一看
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int school,student,start=0;
int range_score[1000010],answer=0;
int school_score[1000010];
int main(){
cin>>school>>student;
for(int i=0;i<school;i++){cin>>school_score[i];}
for(int i=0;i<student;i++){cin>>range_score[i];}
sort(range_score,range_score+student);
sort(school_score,school_score+school);
for(int i=0;i<student;i++){
for(int j=start;j<school;j++){
if(school_score[j]>range_score[i]){
if(range_score[i]-school_score[j-1]>=school_score[j]-range_score[i]){
answer+=school_score[j]-range_score[i];
start=school_score[j];
}else{
answer+=range_score[i]-school_score[j-1];
start=school_score[j-1];
}
break;
}
}
}
cout<<answer;
return 0;
}
急,在线等!!!!!! !!!!!!!!!!!!! !!!!!!