Участник:Timplech/EXPEDI

Материал из DISCOPAL
Перейти к: навигация, поиск

https://www.spoj.com/problems/EXPEDI

Python3

 
import numpy as np
M = int(input())
for t in range(M):
    N = int(input())
    n = 0;
    dists = np.zeros(shape=(N))
    fuels = np.zeros(shape=(N))
    for i in range(N):
        df = list(map(int, input().split()))
        dists[i] = df[0]
        fuels[i] = df[1]
    df = list(map(int, input().split()))
    d = df[0]
    f = df[1]
    dists = d - dists
    while 1:
        if f >= d:
            print(n)
            break
        k = np.argmax(np.multiply((dists <= f), fuels))
        if fuels[k] == 0:
            print(-1)
            break
        f += fuels[k]
        fuels[k] = 0
        n += 1