#6 和10 wa了 想不来怎么回事 下面是蒟蒻代码(QAQ)

P1678 烦恼的高考志愿

HardMonk @ 2021-06-19 22:13:28

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e6 + 10;
int a[N],b[N],c[N];
int main()
{
    int m,n,j = 0;
    long long sum = 0;
    cin >> m >>n;
    int d = n;
    for(int i = 0;i < m;i ++)
    cin >> a[i];
    for(int i = 0;i < n;i ++)
    cin >> b[i];
    sort(a,a + m);
    while(n --)
    {
        int l = 0, r = m - 1;
        while(l <= r)
        {
            int mid = l + r + 1 >> 1;
            if(b[j] < a[0])
            {
                c[j++] = a[0];
                break;

            }
             if(b[j]> a[m-1])
            {
                c[j++] = a[m - 1];
                break;
            }
            if(b[j] >= a[mid]) l = mid + 1;
            else
            r = mid - 1;
             if(a[l] >= b[j] && a[l - 1] <= b[j])
            {
            if(abs(b[j]- a[l]) > abs(b[j]- a[l - 1]))
            c[j++] = a[l - 1];
            else
            c[j++] = a[l];
            break;  
            }

        }
    }
        for(int i = 0;i < d;i++)
            {   
                sum += abs(b[i] - c[i]);
            }
            cout << sum;
            return 0;
 } 

by HardMonk @ 2021-06-19 22:14:07

大佬救救孩子吧(哭


by 刘炳春 @ 2021-08-08 10:03:07

我不知道


|