20分求助

P1678 烦恼的高考志愿

苏黎世 @ 2020-09-29 19:23:14

#include<iostream>
#include<algorithm>
using namespace std;
#define f(X,Y) for(int i = X;i <=Y;++i)
const int maxn = 100005;
int n,m,b,a[maxn],l,r,mid;
long long sum;
void doi(int x)
{
    l = 1; r = m;
    while(l < r){ 
        mid = (l + r) >> 1;
        if( a[mid] <= x) l = mid + 1;
        else r = mid;
    }
    if( b <= a[1] ) sum += (a[1] - b);
    else if(b >= a[m] ) sum += (b - a[m]);
    else sum = sum + min(abs( a[l] - b ),abs(  a[l-1] - b ));
}

void cini()
{
    cin >> m >> n;
    f(1,m) cin >> a[i];
    sort(a + 1,a + n + 1);
    f(1,n) {
        cin >> b;
        doi(b);
    }
    cout << sum;
}

int main()
{
    cini();
    return 0;
}

只A了一个点 wtf?


by Meteorshower_Y @ 2020-09-29 20:25:45

sort(a+1,a+m+1);

by Meteorshower_Y @ 2020-09-29 20:30:37

@苏黎世 n改成m,一共m所学校


by 苏黎世 @ 2020-09-29 20:44:20

@Meteorshower_Y

改了,还是不对aaaa


by 苏黎世 @ 2020-09-29 20:49:28

因为把r赋值成了n而错LJJJJJJJJ

此贴终


|