(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (ts (make-array n :element-type 'uint16))
         (cumul-ts (make-array (+ 1 n) :element-type 'uint16 :initial-element 0))
         (vs (make-array (+ n 1) :element-type 'uint16)))
    (dotimes (i n) (setf (aref ts i) (* 2 (read-fixnum))))
    (dotimes (i n) (setf (aref vs i) (* 2 (read-fixnum))))
    (loop for i from n downto 1
          do (when (> (aref vs (- i 1)) (aref vs i))
               (setf (aref vs (- i 1))
                     (min (aref vs (- i 1))
                          (+ (aref vs i) (aref ts (- i 1)))))))
    (dotimes (i n)
      (setf (aref cumul-ts (+ i 1))
            (+ (aref cumul-ts i) (aref ts i))))
    (let* ((total-time (reduce #'+ ts))
           (next-points (make-array total-time :element-type 'uint16))
           (prev-points (make-array total-time :element-type 'uint16))
           (time-vs (make-array total-time :element-type 'uint16))
           (time-next-vs (make-array total-time :element-type 'uint16))
           (timeline (make-array (+ total-time 1) :element-type 'uint16 :initial-element 0)))
      (dotimes (i n)
        (loop for time from (aref cumul-ts i) below (aref cumul-ts (+ i 1))
              do (setf (aref next-points time) (aref cumul-ts (+ i 1))
                       (aref prev-points time) (aref cumul-ts i)
                       (aref time-vs time) (aref vs i)
                       (aref time-next-vs time) (aref vs (+ i 1))))
        (unless (zerop i)
          (setf (aref time-vs (aref cumul-ts i))
                (min (aref time-vs (aref cumul-ts i))
                     (aref time-vs (- (aref cumul-ts i) 1))))))
      (loop for time from 1 below total-time
            for prev-v = (aref timeline (- time 1))
            do (cond ((and (<= (- (+ 1 prev-v) (- (aref next-points time) time))
                               (aref time-next-vs time))
                           (<= (+ 1 prev-v) (aref time-vs time)))
                      (setf (aref timeline time) (+ 1 prev-v)))
                     ((and (<= (- prev-v (- (aref next-points time) time))
                               (aref time-next-vs time))
                           (<= prev-v (aref time-vs time)))
                      (setf (aref timeline time) prev-v))
                     (t (setf (aref timeline time) (- prev-v 1)))))
      (println (/ (loop for time from 0 below total-time
                        sum (+ (aref timeline time) (aref timeline (+ 1 time))))
                  8d0)))))

#-swank(main)


Measured memory_bytes: 18920