跳到正文

个人记录

111

zyx110824约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
int n,ans,k,son,y[505],l,r,sb[505],cnt;
pair<int,int>a[505],b[505];
// int count(int l,int r,int len){
//     int res=0,tot=0;
//     for(int i=1;i<=n;i++)
//     if(b[i].second>=l&&b[i].second<=r)y[++tot]=b[i].first;
//     int hed=1,til=1;
//     while(til<=tot&&y[til]-y[hed]<=len)til++;
//     while(til>tot||y[til]-y[hed]>len)til--;
//     res=til-hed+1;
//     while()
// }
bool pd(int len){
    int j=1,Max=0;
    for(int i=1;i<=cnt;i++)
      if(sb[i]-sb[j]>len) j++;else Max=max(Max,i-j+1);
    return Max>=k;
}
bool check(int len){
    for(int i=1;i<=n;i++){
        a[i].first;cnt=0;
        for(int j=1;j<=n;j++)
          if(a[i].first-a[j].first<=len) sb[++cnt]=a[j].second;
        sort(sb+1,sb+1+cnt);
        if(pd(len)) return 1;
    }
    return 0;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>k>>n;
    for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second;
    sort(a+1,a+1+n);
    l=1,r=10000;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid))ans=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<ans;
    return 0;
}
原文