问君能有几多愁,恰似一屏WA题上留
查看原帖
问君能有几多愁,恰似一屏WA题上留
948943
Wrongcepted楼主2024/10/7 10:00
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
//This c++ file is for solving problem:
long long m,n;
long long a[100010],sum=0;
int main(){
//	freopen("C:/Users/HD-MOVIE/Downloads/P1678_2.in","r",stdin);
	cin>>m>>n;
	for(int i=1;i<=m;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+m);
	for(int i=1;i<=n;i++){
		long long c;
		cin>>c;
		int l=1,r=n;
		while(l<r){
			int mid=(l+r)/2;
//			cout<<l<<" "<<r<<" "<<mid<<endl;
			if(a[mid]>=c)r=mid;
			else l=mid+1;
		}
//		cout<<a[r]<<endl;
		sum+=abs(a[r]-c);
	}
	cout<<sum; 
	return 0;
}


除了#1全没过

2024/10/7 10:00
加载中...