7 solutions

  • 0
    @ 2022-10-26 22:35:21
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int m,n;
    	cin>>m>>n;
    	int school[m+1];
    	int student[n+1];
    	for(int i=0;i<m;i++)cin>>school[i];
    	for(int i=0;i<n;i++)cin>>student[i];
    	sort(school,school+m);
    	int res=0;
    	for(int i=0;i<n;i++)
    	{
    		int a=abs(student[i]-*lower_bound(school,school+m,student[i]));
    		int b=abs(student[i]-*(lower_bound(school,school+m,student[i])-1));
    		res+=min(a,b);
    	}
    	cout<<res;
    	return 0;
    }

    Information

    ID
    280
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    8
    Tags
    # Submissions
    266
    Accepted
    51
    Uploaded By