居然hcak都能過but一般測試點10ptsWA,求調玄關
查看原帖
居然hcak都能過but一般測試點10ptsWA,求調玄關
1396773
Genshigros楼主2025/7/27 12:16

居然hcak都能過but一般測試點10ptsWA,求調玄關(直接用的貪心卻不知如何二分)

#include<bits/stdc++.h>
#define int long long
//#define debug_mode
using namespace std;
struct node{
	int pos;
	int ls,rs;
}st[500001];
inline bool operator <(node a,node b){
	int anq=min(a.ls,a.rs),bnq=min(b.rs,b.ls);
	int amq=max(a.ls,a.rs),bmq=max(b.rs,b.ls);
	if (anq!=bnq){
		return anq<bnq;
	}else{
		return amq<bmq;
	}
}
inline bool bigcmp(node a,node b){
	return !(a<b);
}
inline bool poscmp(node a,node b){
	return a.pos<b.pos;
}
int n;
int l,m;
signed main(){
	scanf("%d%d%d",&l,&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%d",&st[i].pos);
	}
	for (int i=1;i<=n;i++){
		if (i==1){
			st[i].ls=st[i].pos;
		}else{
			st[i].ls=st[i].pos-st[i-1].pos;
		}
		if (i==n){
			st[i].rs=l-st[i].pos;
		}else{
			st[i].rs=st[i+1].pos-st[i].pos;
		}
	}
	sort(st+1,st+1+n,bigcmp);
	sort(st+1,st+1+(n-m),poscmp);
	int mns=0x7fffffff;
	int newn=n-m;
	for (int i=1;i<=newn;i++){
		if (i==1){
			st[i].ls=st[i].pos;
		}else{
			st[i].ls=st[i].pos-st[i-1].pos;
		}
		if (i==newn){
			st[i].rs=l-st[i].pos;
		}else{
			st[i].rs=st[i+1].pos-st[i].pos;
		}
		mns=min(mns,min(st[i].ls,st[i].rs));
	}
	cout<<mns;
}
2025/7/27 12:16
加载中...