样例过全WA
查看原帖
样例过全WA
1198866
yinY_楼主2025/1/27 21:05
public class p3853 {
	static int l,n,k;
	static int[] ar;
	public static void main(String[] args) {
		Scanner scanner=new Scanner( System.in);
		l=scanner.nextInt();
		n=scanner.nextInt();
		k=scanner.nextInt();
		ar=new int[n+1];
		for (int i = 1; i <=n; i++) {
			ar[i]=scanner.nextInt();
		}
		int left=1,right=l;
		
		while(left<=right) {
			int mid=(left+right)>>1;
			int jd=judge(mid);
			if(jd==0) {
				left=mid+1;
				
			}else if (jd==1) {
				right=mid-1;
			}else {
				System.out.println(mid);
				System.exit(0);
			} 
		}
		
		
	}
	private static int judge(int mid) {
		// TODO Auto-generated method stub
		int ind=0,tot=0;
		for (int i =2 ; i <=n; i++) {
			if (ar[i]-ar[i-1]>=mid) {
				tot++;
			}
		}
		if (tot>k) {
			return 0;
		}
		else if (tot<k) {
			return 1;
		}else {
			return 2;
		}
	}
}
2025/1/27 21:05
加载中...