动态规划&vector向量
#include
#include
using namespace std;
long long C(long long n){
return (n-1) * n / 2;
}
int main()
{
long long n, d, count = 0;
cin>> n>> d;
vector v(n);
for (int i = 0, j = 0; i < n; i++) {
cin>> v[i];
while (i >= 2 && (v[i] - v[j]) > d) {
j++;
}
count += C(i - j);
}
cout << count % 99997867;
return 0;
}
#include
#include
using namespace std;
long long C(long long n){
return (n-1) * n / 2;
}
int main()
{
long long n, d, count = 0;
cin>> n>> d;
vector
for (int i = 0, j = 0; i < n; i++) {
cin>> v[i];
while (i >= 2 && (v[i] - v[j]) > d) {
j++;
}
count += C(i - j);
}
cout << count % 99997867;
return 0;
}
全部评论
相关推荐