大佬救救我,wa了四个,2,4,8,9
查看原帖
大佬救救我,wa了四个,2,4,8,9
1180146
kaito_936楼主2024/4/11 20:41

我感觉我这玩意用的没毛病啊,要是能提供给我后面两组的数据也行。

#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
long long int n, c, temp, ans,a[200001],j,l,i;

int main(){
    cin >> n >> c;
    

    for (i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    a[n] = a[n - 1] + 1;
    for (i = 0; i <= n; i++) {
	while (a[i] - a[j] > c&&a[j]==a[l]) j++;
	if (j != l) {
	    ans += temp * (j - l);
	    temp = 0;
	    l = j;
	}
	if (a[i] - a[j] == c) temp++;
    }
    cout << ans;

    return 0;
 }
2024/4/11 20:41
加载中...