summaryrefslogtreecommitdiffstats
path: root/Main/Python/2022/S3.py
blob: 60549ed4051211d00c5a5719b6a2f862ecd61e0b (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# WIP
n, m, k = tuple(map(int, input().split()))

# N number of notes
# M highest note
# K number good samples

# best piece
# 1, 2, 1, 2, 1, 2

# MAX length of good sample = M
# number of good samples in pattern core = m*(m+1)/2
output = -1
for M in range(1, 1+m):
    # num_good = (m * (m+1) /2) * n//m + (n%m * (n%m+1)/2)
    num_good = n * (n + 1) / 2 - (n - M) * (n - M + 1) / 2
    # print(M, num_good, end= ' | ')
    # for i in range(n):
    #     print((i % M) + 1, end=" ")
    # print()
    if num_good == k:
        output = M
        # break

if output > 0:
    for i in range(n):
        print(m-((i % output) + 1) + 1, end=" ")
else:
    print(output)

# n = 5, m = 4
# 1 2 3 4 1

# 1, 2, 3, 4, 1,(5)
# 1 2, 2 3, 3 4, 4 1, (4)
# 1 2 3, 2 3 4, 3 4 1, (3)
# 1 2 3 4, 2 3 4 1 (2)
# total = 5+4+3+2 = 14

# input : n=6, m=4
# 1 2 3 4 1 2
# 1, 2, 3, 4 ,1, 2 (6)
# 1 2, 2 3, 3 4, 5 1, 1 2 (5)
# 1 2 3, 2 3 4, 3 4 1, 4 1 2 (4)
# 1 2 3 4, 2 3 4 1, 3 4 1 2 (3)
# good samples = 6(6+1)/2 - (6-4)(6-4+1)/2 = 21-3 = 18

# n = 10, m = 2
# 1 2 1 2 1 2 1 2 1 2
# 1 2 1 2 1 2 1 2 1 2 (10)
# 12 21 12 21 12 21 12 21 12 (9)
#good samples = 10 + 9= 19
# 10(11)/2 - (10-2)(10-2+1)/2 = 55 - 36 = 19

# n = 11, m = 2
# 1 2 1 2 1 2 1 2 1 2 1
# 1 2 1 2 1 2 1 2 1 2 1 (11)
# 12 21 12 21 12 21 12 21 12 21 (10)
# total = 11 + 10 = 21