# Python implementation of the approach
# Function for the distribution of the number
def distribution(n, k, l, r, S, Sk):
a = [0] * n;
len = k;
temp, rem, s = 0, 0, 0;
diff = S - Sk;
for i in range(len):
# Distribute the number
# among k elements
temp = Sk / k;
rem = Sk % k;
if (temp + rem >= l and temp + rem <= r):
a[i] = temp;
elif(temp + rem > r):
a[i] = r;
elif(temp + rem < r):
print("-1");
return;
Sk = Sk - a[i];
k = k - 1;
# If there is some remaining
# sum to distribute
if (Sk > 0):
print("-1");
return;
# If there are elements remaining
# to distribute i.e. (n - k)
if (len != 0):
k = n - len;
for i in range(len, n):
# Divide the remaining sum into
# n-k elements
temp = diff / k;
rem = diff % k;
if (temp + rem >= l and temp + rem <= r):
a[i] = temp;
elif(temp + rem > r):
a[i] = r;
elif(temp + rem < r):
print("-1");
return;
diff = diff - a[i];
k = k - 1;
if (diff != 0):
print("-1");
return;
# Print the distribution
for i in range(n):
print(int(a[i]), end=" ");
# Driver code
if __name__ == '__main__':
n, k, l, r, S, Sk = 5, 3, 1, 5, 13, 9;
distribution(n, k, l, r, S, Sk);
# This code is contributed by PrinciRaj1992