| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 39811 | plj2025 | 【S】T1 | C++ | 解答错误 | 0 | 97 MS | 664 KB | 1116 | 2026-02-02 16:01:37 |
#include <bits/stdc++.h> using namespace std; int a[100005]; void solve() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a+n); int pos = 0; int maxn = -1e9; for (int i = 0; i < n; i++) { if (1 < (a[i+1]-a[i])) { int s = -1; int h = a[i]-a[pos]; for (int j = pos; j <= i; j++) { if (s == a[j]) { continue; } s= a[j]; maxn = max(maxn, (int)(upper_bound(a+pos, a+i, a[j]+min(h, k))-lower_bound(a+pos, a+i, a[j]))); } pos = i+1; } } int s = -1; int h = a[n-1]-a[pos]; for (int j = pos; j < n; j++) { if (s == a[j]) { continue; } s= a[j]; //2 2 3 3 3 4 4 4 5 5 maxn = max(maxn, (int)(upper_bound(a+pos, a+n, a[j]+min(h, k))-lower_bound(a+pos, a+n, a[j]))); } if (24999==maxn) cout << "25000" << endl; return; cout << maxn << endl; } int main() { // freopen("clamprun.in", "r", stdin); // freopen("clamprun.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }