Submission #5285187


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/







int N, D, R[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> D;
	rep(i, 0, N) cin >> R[i];
	sort(R, R + N);

	ll ans = 0;
	int r = 0;
	rep(l, 0, N) {
		while (r < N and R[r] - R[l] <= D) r++;
		
		int other = r - l - 1;
		ans += 1LL * (other) * (other - 1) / 2;
	}
	cout << ans << endl;
}

Submission Info

Submission Time
Task C - Make a Team
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1652 Byte
Status AC
Exec Time 18 ms
Memory 640 KB

Judge Result

Set Name all sample
Score / Max Score 300 / 300 0 / 0
Status
AC × 28
AC × 3
Set Name Test Cases
all sample01, sample02, sample03, test01, test02, test03, test04, test05, test06, test07, test08, test09, test10, test11, test12, test13, test14, test15, test16, test17, test18, test19, test20, test21, test22, test23, test24, test25
sample sample01, sample02, sample03
Case Name Status Exec Time Memory
sample01 AC 1 ms 256 KB
sample02 AC 1 ms 256 KB
sample03 AC 1 ms 256 KB
test01 AC 1 ms 256 KB
test02 AC 1 ms 256 KB
test03 AC 1 ms 256 KB
test04 AC 15 ms 640 KB
test05 AC 17 ms 640 KB
test06 AC 12 ms 512 KB
test07 AC 14 ms 512 KB
test08 AC 9 ms 512 KB
test09 AC 15 ms 640 KB
test10 AC 14 ms 640 KB
test11 AC 18 ms 640 KB
test12 AC 17 ms 640 KB
test13 AC 17 ms 640 KB
test14 AC 14 ms 640 KB
test15 AC 16 ms 640 KB
test16 AC 18 ms 640 KB
test17 AC 17 ms 640 KB
test18 AC 15 ms 640 KB
test19 AC 12 ms 640 KB
test20 AC 17 ms 640 KB
test21 AC 17 ms 640 KB
test22 AC 17 ms 640 KB
test23 AC 16 ms 640 KB
test24 AC 16 ms 640 KB
test25 AC 1 ms 256 KB