Help,为什么错了?

P1678 烦恼的高考志愿

steve255 @ 2023-02-26 20:31:46

#include<bits/stdc++.h>

using namespace std;

int a[1000002];
int b[1000002];

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];
    }
    int cnt=0;
    sort(b+1,b+1+n);
    for(int i=1;i<=n;i++){
        int key=a[i];
        int tmp=lower_bound(b+1,b+1+n,key)-b;
        int f=tmp-1;
        if(a[i]-tmp>a[i]-f)cnt+=f;
        else cnt+=tmp;
    }
    cout<<cnt;
    return 0;
}

|