blob: ab65f30e6bffde19e725d593c52c48b5a95a17fe (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
(define (read-line n) (if (> n 0) (cons (read) (read-line (1- n))) '()))
(let test ((t (read)))
(when (> t 0)
(display
(let* ((n (read)) (w (read-line n)) (l (read-line n))
(i (let range ((k 1) (m n))
(if (> m 0) (cons k (range (1+ k) (1- m))) '()))))
(let loop ((last 0)
(frogs (map cdr (sort (map list w i l)
(lambda (u v) (< (car u) (car v)))))))
(if (null? frogs)
0
(let* ((first (car frogs)) (pos (car first)) (len (cadr first))
(hits (if (> pos last) 0 (1+ (quotient (- last pos) len)))))
(+ hits (loop (+ pos (* hits len)) (cdr frogs))))))))
(newline)
(test (1- t))))
|