mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-28 01:36:27 +00:00
P1678 烦恼的高考志愿
R44433175
This commit is contained in:
parent
b425bd8067
commit
7db766b4e7
28
problem/P1678/P1678.cpp
Normal file
28
problem/P1678/P1678.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int m, n, q, ans, a[100005];
|
||||
|
||||
int main() {
|
||||
cin >> m >> n;
|
||||
for (int i = 0; i < m; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
sort(a, a + m);
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> q;
|
||||
int p = lower_bound(a, a + m, q) - a;
|
||||
if (p == m) {
|
||||
ans += q - a[m - 1];
|
||||
}
|
||||
else if (p == 0) {
|
||||
ans += a[0] - q;
|
||||
}
|
||||
else {
|
||||
ans += min(abs(a[p] - q), abs(q - a[p - 1]));
|
||||
}
|
||||
}
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user