30分求助
查看原帖
30分求助
1036708
12345limengqi楼主2023/11/10 15:51
#include <iostream>
#include <algorithm>
using namespace std;
unsigned long long int n, m;
unsigned long long int cc = 0;
unsigned long long int t;
unsigned long long int mm = 1000000;
int main () {
	cin >> m >> n;
	 unsigned long long a[n];// 学生估分成绩 
	 unsigned long long b[m];// 学校的预计录取分数 
	for(int i = 0; i < m; i++){
		cin >> b[i];
	}
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(a[i] > b[j]){
				t = a[i] - b[j];	
			}
			else {
				t = b[j] - a[i];
			}
			if(mm > t){
				mm = t;
			}
		}
		cc += mm;
		mm = 1000000;
	}
	cout << cc;
	return 0;
}
2023/11/10 15:51
加载中...