-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
36 lines (28 loc) · 1.05 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
namespace Beautiful_Triplets {
class Program {
public static int BeautifulTriplets(int d, int[] ar) {
int beautifulTriplets = 0;
for (int i = 0; i < ar.Length - 2; i++) {
for (int j = i + 1; j < ar.Length - 1; j++) {
if ((ar[j] - ar[i]) == d) {
for (int k = j + 1; k < ar.Length; k++) {
if ((ar[k] - ar[j]) == d) {
beautifulTriplets++;
}
}
}
}
}
return beautifulTriplets;
}
static void Main(string[] args) {
string[] nd = Console.ReadLine().Split(' ');
int n = Convert.ToInt32(nd[0]);
int d = Convert.ToInt32(nd[1]);
int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp));
int result = BeautifulTriplets(d, ar);
Console.WriteLine(result);
}
}
}