$\color{red}0$分求助

P1678 烦恼的高考志愿

farmer_snack @ 2022-05-21 20:29:22

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int m;
    scanf("%d",&m);
    int n;
    scanf("%d",&n);
    int s[100000];
    int c[100000];
    for(int a=0;a<m;a++)
    {
        scanf("%d",&s[a]);
        //cin>>s[a];
    }
    for(int a=0;a<n;a++)
    {
        scanf("%d",&c[a]);
        //cin>>c[a];
    }
    int ans1,ans2,ans=0,cnt=0;
    for(int a=0;a<n;a++)
    {
        for(int b=0;b<m;b++)
        {
            cnt=ans1;
            ans1=c[a]-s[m];
            ans2=s[m]-c[a];
            if(ans2<ans1)
            {
                ans1=ans2;
            }
            if(cnt>ans1)
            {
                cnt=ans1;
            }
        }
        ans=ans+cnt;
    }
    cout<<ans;
}

by _Haoomff_ @ 2022-05-21 20:38:25

@违规用户名SJ1DJMXN az,要是真这么简单那么应该是红题吧


by Node_Edge @ 2022-05-21 20:43:55

二分! 二分! 二分!


by xuorange @ 2022-05-21 21:04:03

@违规用户名SJ1DJMXN ?在帖子题目里居然能用LateX


by wuwendongxi @ 2022-05-21 22:54:30

@xuorange 这是markdown


by farmer_snack @ 2022-05-22 08:25:53

@Node_Edge https://www.luogu.com.cn/record/76171735


by Node_Edge @ 2022-05-22 10:01:02

@违规用户名SJ1DJMXN 可以看下题解,换个方法

注意 n,m \le 100,000


by lion0514 @ 2022-05-22 10:04:56

@wuwendongxi 你搁着markdown呢


by xuorange @ 2022-05-23 07:18:58

@wuwendongxi ?

$\color{red}0$

显然是LateX


|