-
Notifications
You must be signed in to change notification settings - Fork 0
/
Administrative Difficulties.py
82 lines (73 loc) · 2.71 KB
/
Administrative Difficulties.py
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
import math
class car:
def __init__(self, name, price, pickupCost, driveCost) -> None:
self.name = name
self.price = price
self.pickupCost = pickupCost
self.driveCost = driveCost
self.picked = False
self.currDriver = ""
class agent:
def __init__(self, name) -> None:
self.name = name
self.currentCar = ""
self.outcome = 0
def findCarObj(name): #returns position of car in list as integer
it = 0
for item in cars:
if item.name == name:
return it
it+=1
def findAgentObj(name): #returns position of car in list as integer
it = 0
for item in agents:
#print(f"{name} {item.name} {it}")
if item.name == name:
return it
it+=1
if it > len(agents):
return -1
cases = int(input())
n, m = list(map(int, input().split()))
cars = []
agents = []
for _ in range(n):
carname, carprice, carpickupcost, cardrivecost = input().split()
cars.append(car(carname, int(carprice), int(carpickupcost), int(cardrivecost)))
for _ in range(m):
t, s, e, x = input().split()
if findAgentObj(s) == -1 or findAgentObj(s) == None:
agents.append(agent(s))
if e == "p":
it2 = findCarObj(x)
cars[it2].picked = True
it = findAgentObj(s)
if agents[it].currentCar != "":
agents[it].outcome = -1
else:
agents[it].currentCar = x
agents[it].outcome += cars[it2].pickupCost
elif e == "r":
it = findAgentObj(s) #finding current pertinent agent\
#print(f"agent number {it}")
it2 = findCarObj(agents[it].currentCar) #finding agents current car
if cars[it2].picked != True: #car wasnt in use, can't be returned
agents[it].outcome = -1
else: #car was in use, can be returned
if agents[it].outcome != -1: #dont bother with calculation if already an inconsistent outcome
agents[it].outcome += (cars[it2].driveCost * int(x)) #calculating outcome with the drive cost of the car and miles driven
agents[it].currentCar = ""
cars[it2].picked = False
elif e == "a":
it = findAgentObj(s)
it2 = findCarObj(agents[it].currentCar)
#print(f"agent {it} car {it2}")
if it2 is None: #car wasn't in use, cant have an accident
agents[it].outcome = -1
else:
if agents[it].outcome != -1:
agents[it].outcome += math.ceil(cars[it2].price * (int(x)/100))
for agent in sorted(agents, key=lambda x: x.name):
if agent.currentCar != "":
agent.outcome = -1
print(f"{agent.name} {agent.outcome if agent.outcome >-1 else 'INCONSISTENT'}")