Tävlingsprogrammering/Uppgifter/Spotify Connect

Lösningsförslag i Python 3

from sys import stdin
 
n = int(input())
input_data = list()
input_append = input_data.append
 
for x in range(n):
    data = stdin.readline().split()
    data[0] = int(data[0].lstrip('0'))
 
    if data[1] == 'mobile':
        data[0] += 100
 
    if data[2] == 'play':
        data[2] = True
    else:
        data[2] = False
 
    input_append((data[0], data[2]))
 
input_data.sort()
 
time = 0
data = list()
data_app = data.append
for x in input_data:
    if x[1]:
        data_app(x[0])
    else:
        if len(data) > 0:
            time +=  x[0] - data[0]
            del data[:]
print(time)