美文网首页
CodeFoeces-940A

CodeFoeces-940A

作者: ss5smi | 来源:发表于2018-02-25 13:14 被阅读0次

题目

原题链接:A. Points on the line

题意

给出n个数字,去掉任意个数字保证任意两个数字的差不大于d。

代码

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,d,s[110],ans=0;
    cin>>n>>d;
    for(int i=0; i<n; i++) {
        cin>>s[i];
    }
    sort(s,s+n);
    if(s[n-1]-s[0]<=d) {
        printf("0\n");
        return 0;
    }
    for(int i=0; i<n; i++) {
        for(int j=i; j<n; j++) {
            if(s[j]-s[i]<=d) {
                ans=max(ans,j-i+1);
            }
        }
    }
    cout<<n-ans;
    return 0;
}

相关文章

  • CodeFoeces-940A

    题目 原题链接:A. Points on the line 题意 给出n个数字,去掉任意个数字保证任意两个数字的差...

网友评论

      本文标题:CodeFoeces-940A

      本文链接:https://www.haomeiwen.com/subject/sxvqxftx.html