Hyper Checkers Score Counting
InterviewTime limit1sMemory limit512 MB
Count distinct ordered triples (a,b,c) drawn from n given cards such that max(a,b,c) <= k * min(a,b,c).
- Level
Medium6 of 10
- Topics
- Sorting, Two pointers, Math, Combinatorics
- Solved
- No attempts yet
Problem
Andrey works as a judge at a hyper checkers championship. Each game of hyper checkers involves three players. During the game each player earns a positive integer score. If after the game the first player has points, the second has points, and the third has points, the game is said to have ended with the score .
Andrey knows that the rules of hyper checkers are set up so that in the result of a game the scores of any two players differ by no more than a factor of .
After a match, Andrey displays its result by placing three cards with the players' scores on a special board. For this he has a set of cards with the numbers written on them. To find out how ready he is for the championship, Andrey wants to know how many distinct score options he can display on the board using the cards he has.
Given the number and the numbers on the cards Andrey has, write a program that determines the number of distinct score options Andrey can display on the board.
Input
The first line of the input file contains two integers: and (, ).
The second line of the input file contains integers ().
Output
The output file must contain one integer: the number of distinct score options sought.
Hint
In the given example Andrey can display the following score options: 1:1:2, 1:2:1, 2:1:1, 1:2:2, 2:1:2, 2:2:1, 2:2:3, 2:3:2, 3:2:2. Other triples of numbers that can be formed using the available cards do not satisfy the condition that the scores of any two players differ by no more than a factor of .