50pts,江湖救急(绿黑灯)

P1678 烦恼的高考志愿

syy999 @ 2024-07-05 10:40:09

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 100000
#define lm 9223372036854775807
int m,n,a[N],b[N];
signed main(){
    cin>>m>>n;
    for(int i=1;i<=m;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    } 
    int l=0,il;
    for(int i=1;i<=n;i++){
        il=lm;
        for(int j=1;j<=m;j++){
            il=min(il,abs(b[i]-a[j]));
        }
        l+=il;
    }
    cout<<l;
    return 0;
}

by yangyang826 @ 2024-07-05 11:15:02

use 二分


by syy999 @ 2024-07-08 10:15:56

@yangyang826 怎么用


|