Submission #17509960


Source Code Expand

Copy
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(L, A, B):
    A = [0] + A + [L + 1]
    B = [0] + B + [L + 1]
    A = [y - x - 1 for x, y in zip(A, A[1:])]
    B = [y - x - 1 for x, y in zip(B, B[1:])]
    N = len(A)
    j = 0
    frm = [[] for _ in range(N)]
    for i in range(N):
        if A[i] == 0:
            continue
        while j < N and B[j] == 0:
            j += 1
        if j == N:
            break
        if A[i] > B[j]:
            return -1
        B[j] -= A[i]
        frm[j].append(i)
    ans = 0
    for j in range(N):
        X = frm[j]
        if not X:
            continue
        l, r = X[0], X[-1]
        l = min(l, j)
        r = max(r, j)
        ans += r - l
    return ans

N, L = map(int, readline().split())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

print(main(L, A, B))

Submission Info

Submission Time
Task C - Penguin Skating
User maspy
Language Python (3.8.2)
Score 700
Code Size 964 Byte
Status AC
Exec Time 186 ms
Memory 35000 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 43
Set Name Test Cases
Sample 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt
All 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 19 ms 9052 KB
00-sample-002.txt AC 20 ms 9236 KB
00-sample-003.txt AC 22 ms 9208 KB
01-001.txt AC 21 ms 9204 KB
01-002.txt AC 28 ms 8980 KB
01-003.txt AC 36 ms 14332 KB
01-004.txt AC 99 ms 28356 KB
01-005.txt AC 59 ms 14680 KB
01-006.txt AC 60 ms 15080 KB
01-007.txt AC 64 ms 16524 KB
01-008.txt AC 91 ms 22352 KB
01-009.txt AC 152 ms 30780 KB
01-010.txt AC 70 ms 18316 KB
01-011.txt AC 128 ms 28144 KB
01-012.txt AC 121 ms 25984 KB
01-013.txt AC 117 ms 32308 KB
01-014.txt AC 120 ms 33692 KB
01-015.txt AC 156 ms 32648 KB
01-016.txt AC 148 ms 32376 KB
01-017.txt AC 154 ms 33112 KB
01-018.txt AC 154 ms 33440 KB
01-019.txt AC 145 ms 30480 KB
01-020.txt AC 143 ms 30620 KB
01-021.txt AC 148 ms 31856 KB
01-022.txt AC 141 ms 31200 KB
01-023.txt AC 160 ms 33428 KB
01-024.txt AC 153 ms 33408 KB
01-025.txt AC 160 ms 34016 KB
01-026.txt AC 153 ms 33436 KB
01-027.txt AC 151 ms 30908 KB
01-028.txt AC 147 ms 31508 KB
01-029.txt AC 151 ms 31852 KB
01-030.txt AC 146 ms 30660 KB
01-031.txt AC 168 ms 33692 KB
01-032.txt AC 186 ms 35000 KB
01-033.txt AC 179 ms 34788 KB
01-034.txt AC 180 ms 34480 KB
01-035.txt AC 169 ms 32400 KB
01-036.txt AC 156 ms 31312 KB
01-037.txt AC 176 ms 33864 KB
01-038.txt AC 162 ms 31532 KB
01-039.txt AC 166 ms 31592 KB
01-040.txt AC 158 ms 31420 KB