n = 4
k = 1
t = 1
ob = list(map(int, "1331"))
# 1 - spotkanie biuro
# 2 - spotkanie zdalne
# 3 - czas wolny
def makeplan(a):
plan = []
for i in a:
if i == 1:
plan.append("B")
elif i == 2:
plan.append("Z")
elif i == 3:
plan.append("W")
return plan
def f():
opuszczone_spotkania = 0
for i in range(n):
if ob[i] in (1, 2):
opuszczone_spotkania += 1
if opuszczone_spotkania > k:
# I od biura
res1 = 0
plan = makeplan(ob)
for i in range(ob.count(1)):
for j in range(len(ob)):
if ob[j] == 1:
if plan[j] == "P":
continue
else:
if plan.count("P") > 0:
idx = len(ob)-1-plan[::-1].index("P")
plan[idx:j] = ["R"]*(j-idx)
plan[j] = "B"
plan[j+1:j+t+1] = ["P"]*t
for m in range(len(ob)):
if plan[m] == "R" and ob[m] == 2:
opuszczone_spotkania -= 1
else:
plan[j-t:j] = ["P"]*t
plan[j] = "B"
plan[j+1:j+t+1] = ["P"]*t
opuszczone_spotkania -= 1
if opuszczone_spotkania == k:
break
else:
for j in range(ob.count(2)):
for m in range(len(ob)):
if ob[m] == 2 and not plan[m] in ("P", "R", "B"):
plan[m] = "Z"
opuszczone_spotkania -= 1
if opuszczone_spotkania == k:
break
res1 = plan.count("W")
# II od zdalnego
res2 = 0
plan = makeplan(ob)
for i in range(ob.count(2)):
for j in range(len(ob)):
if ob[j] == 2:
plan[j] = "Z"
opuszczone_spotkania -= 1
if opuszczone_spotkania == k:
break
else:
for j in range(ob.count(1)):
for m in range(len(ob)):
if ob[m] == 1:
if plan[m] == "P":
continue
else:
if plan.count("P") > 0:
idx = len(ob)-1-plan[::-1].index("P")
if 2 in ob[idx:j+t+1]:
continue
else:
plan[idx:j] = ["R"]*(j-idx)
plan[j] = "B"
plan[j+1:j+t+1] = ["P"]*t
else:
if 2 in ob[j-t:j+t+1]:
continue
else:
plan[j-t:j] = ["P"]*t
plan[j] = "B"
plan[j+1:j+t+1] = ["P"]*t
opuszczone_spotkania -= 1
if opuszczone_spotkania == k:
break
res2 = plan.count("W")
if opuszczone_spotkania > k:
return -1
else:
return max(res1, res2)
else:
return n
print(f())
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | n = 4 k = 1 t = 1 ob = list(map(int, "1331")) # 1 - spotkanie biuro # 2 - spotkanie zdalne # 3 - czas wolny def makeplan(a): plan = [] for i in a: if i == 1: plan.append("B") elif i == 2: plan.append("Z") elif i == 3: plan.append("W") return plan def f(): opuszczone_spotkania = 0 for i in range(n): if ob[i] in (1, 2): opuszczone_spotkania += 1 if opuszczone_spotkania > k: # I od biura res1 = 0 plan = makeplan(ob) for i in range(ob.count(1)): for j in range(len(ob)): if ob[j] == 1: if plan[j] == "P": continue else: if plan.count("P") > 0: idx = len(ob)-1-plan[::-1].index("P") plan[idx:j] = ["R"]*(j-idx) plan[j] = "B" plan[j+1:j+t+1] = ["P"]*t for m in range(len(ob)): if plan[m] == "R" and ob[m] == 2: opuszczone_spotkania -= 1 else: plan[j-t:j] = ["P"]*t plan[j] = "B" plan[j+1:j+t+1] = ["P"]*t opuszczone_spotkania -= 1 if opuszczone_spotkania == k: break else: for j in range(ob.count(2)): for m in range(len(ob)): if ob[m] == 2 and not plan[m] in ("P", "R", "B"): plan[m] = "Z" opuszczone_spotkania -= 1 if opuszczone_spotkania == k: break res1 = plan.count("W") # II od zdalnego res2 = 0 plan = makeplan(ob) for i in range(ob.count(2)): for j in range(len(ob)): if ob[j] == 2: plan[j] = "Z" opuszczone_spotkania -= 1 if opuszczone_spotkania == k: break else: for j in range(ob.count(1)): for m in range(len(ob)): if ob[m] == 1: if plan[m] == "P": continue else: if plan.count("P") > 0: idx = len(ob)-1-plan[::-1].index("P") if 2 in ob[idx:j+t+1]: continue else: plan[idx:j] = ["R"]*(j-idx) plan[j] = "B" plan[j+1:j+t+1] = ["P"]*t else: if 2 in ob[j-t:j+t+1]: continue else: plan[j-t:j] = ["P"]*t plan[j] = "B" plan[j+1:j+t+1] = ["P"]*t opuszczone_spotkania -= 1 if opuszczone_spotkania == k: break res2 = plan.count("W") if opuszczone_spotkania > k: return -1 else: return max(res1, res2) else: return n print(f()) |
English