Multi-level marketing related challenge.
A peer wants to get rewarded. So it attracted N
investors (N>=1
), each i-th investor invested x[i]
. When a total sum exceeds threshold x[0]+x[1]+...+x[N-1] >= T
a peer could be rewarded. But only if a following conditions are satisfied:
- Minimum amount of investors should be greater than
M
, (M<=N
) - For at least one integer
k
, wherek>=M
andk<=N
, anyk
investors have to invest at leastT/k
each;
Given N, x[], T, M
you should determine whether the peer's reward is generated or not (boolean result, "yes" or "no"). Shortest code wins.
Examples:
N=5; M=3; T=10000
, in order to generate the peer's reward one of the following must be satisfied:
- any 3 invested at least 3334 each
- any 4 invested at least 2500 each
- all 5 invested at least 2000 each
N=6; M=2; T=5000
:
- any 2 invested at least 2500 each
- any 3 invested at least 1667 each
- any 4 invested at least 1250 each
- any 5 invested at least 1000 each
- all 6 invested at least 834 each
generalized: for any k
, where k>=M
and k<=N
:
- any
k
ofN
investors invested at leastT/k
each
Test cases:
format:
N, x[], T, M -> correct answer
6, [999, 999, 59, 0, 0, 0], 180, 3 -> 0
6, [0, 60, 0, 60, 60, 0], 180, 3 -> 1
6, [179, 89, 59, 44, 35, 29], 180, 3 -> 0
6, [179, 89, 59, 44, 35, 30], 180, 3 -> 1
6, [179, 89, 59, 44, 36, 29], 180, 3 -> 1
6, [179, 90, 59, 44, 35, 29], 180, 3 -> 0
6, [30, 30, 30, 30, 29, 30], 180, 3 -> 0
6, [30, 30, 30, 30, 30, 30], 180, 3 -> 1
len(x)
will be shorter than writingN
. That is made, because for dynamically allocated arrayx
in C there is no directlen(x)
function - so you may always refer to length asN
. For convenience, you may consider all input dataN, x[], T, M
as some externally defined constants, or some language built-ins. \$\endgroup\$true
and truthy value forfalse
? \$\endgroup\$