Solutions to Volunteer Questions for College Entrance Examination

Title link: https://nanti.jisuanke.com/t/T1874

topic

Topic

Mr. Suantou of the computer competition team finally ended the evil college entrance examination. However, as the class leader, he could not relax. The class teacher gave him a difficult task: to help students find the most reasonable college application plan. But Mr. Suantou was too busy, so he thought of you, who is also a computer competition team, and ask you to help him complete this difficult task.
According to the estimated scores of n students, a school is recommended to each student. The difference between the school’s estimated score and the student’s estimated score is required to be the smallest (high or low, after all, it is an estimated score). The minimum value is not satisfied degree. Find the minimum sum of dissatisfaction among all students.

Input format

Insert picture description here

Output format

There is one row of output data, which is the sum of the smallest dissatisfaction.

Sample

Sample input

4 3
513 598 567 689
500 600 550

Sample output

32

···································A gorgeous dividing line··········· ···························

Ideas

Two points! ! !

Bidding

#include<bits/stdc++.h>
using namespace std;
int n,m,x[100001],y;
long long ans;
//	freopen("exam.in","r",stdin);
//	freopen("exam.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>x[i];
    sort(x+1,x+n+1);
    while(m--){
    
    
        cin>>y;
        int l=0,r=n+1;
        while(l<r){
    
    
            int mid=(l+r)>>1;
            if(x[mid]<=y)l=mid+1;
			else r=mid;
        }
        if(y<=x[1])ans+=x[1]-y;
        else ans+=min(abs(x[l-1]-y),abs(x[l]-y));
    }
    cout<<ans<<endl;
    return 0;
}

However...
it seems that there is one (billion) point problem

测评信息
================================================
测评用例 1:正确通过 [1.000 毫秒,824 KB]
---------------------------
测评用例 2:正确通过 [1.000 毫秒,824 KB]
---------------------------
测评用例 3:正确通过 [1.000 毫秒,824 KB]
---------------------------
测评用例 4:正确通过 [31.000 毫秒,824 KB]
---------------------------
测评用例 5:正确通过 [33.000 毫秒,824 KB]
---------------------------
测评用例 6:正确通过 [29.000 毫秒,824 KB]
---------------------------
测评用例 7:正确通过 [32.000 毫秒,824 KB]
---------------------------
测评用例 8:正确通过 [18.000 毫秒,824 KB]
---------------------------
测评用例 9:答案错误 [48.000 毫秒,824 KB]
用例输入:
100000 100000
79808 438278 497258 569994 60803 426031 660311 67857 808358 728753 839982 886334……
531664 661391 452414 199274 618734 170720 842030 385999 380027 680768 94886 5991……

用例正确输出:
500200

你的输出:
500173
---------------------------
测评用例 10:正确通过 [48.000 毫秒,824 KB]

结果
================================================
共 10 组测评用例,通过 9 组。

总分
================================================
9

This is the unprecedented data

True standard

#include<bits/stdc++.h>
using namespace std;
long long p1,p2,d1,d2,ans,x,num[1100000],n,m;
int main(){
    
    
//	freopen("exam.in","r",stdin);
//	freopen("exam.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    cin>>m>>n;
    for(int i=0;i<m;i++)cin>>num[i];
    sort(num,num+m);
    while(n--){
    
    
        cin>>x;
        p1=lower_bound(num,num+m,x)-num;p2=p1-1;d1=d2=20000000;
        if(p1!=m)d1=num[p1]-x;
        if(p2!=-1)d2=x-num[p2];
        ans+=min(d1,d2);
    }
    cout<<ans<<endl;
    return 0;
}

Perfect AC

Shameless please like + follow + favorite

Guess you like

Origin blog.csdn.net/Richard_1101/article/details/109275888