• 2257 Booking Seats

    Time Limit : 2000/1000 MS(Java/Others) | Memory Limit : 131072/65536 KB(Java/Others)

    Submits : 9 | Solved : 3

    Description

    John and Brus are going to a theater to see a very interesting movie. They would like to have seats next to each other in the same row. The theater contains n rows, with m seats in each row. Rows are numbered 1 to n from front to back, and seats are numbered 1 to m from left to right. Some of the seats are already reserved, but John and Brus can book any of the available seats.  You are given  one line with rows and one line with seats. The i-th elements of row and seat are the row number and seat number of the i-th reserved seat. All remaining seats are available. Return the number of ways for John and Brus to book two available seats next to each other in the same row.
    Notes
    -
    Two bookings are considered different only if one contains a seat that the other does not contain. In other words, they don't need to decide which seat John sits in and which seat Brus sits in.
    Constraints
    -
    n and m will each be between 1 and 50, inclusive.
    -
    row will contain between 1 and 50 elements, inclusive.
    -
    row and seat will contain the same number of elements.
    -
    Each element of row will be between 1 and n, inclusive.
    -
    Each element of seat will be between 1 and m, inclusive.
    -
    All pairs (row[i], seat[i]) will be distinct.
    

    Input

      In the first line there wiil be threee numbers n,m and l,meanings that
    thert are n rows and m seats per row,and l seats are reserved;
      And then two lines,one line l numbers meanings row number, one line l numbers meanings seat number;

    Output

    Output the number of ways for John and Brus to book two available seats next to each other in the same row.
    

    Sample Input

    2
    3
    2
    1 2
    2 3
    2
    3
    6
    1 1 1 2 2 2
    1 2 3 1 2 3
    4
    7
    1
    1
    1
    10
    8
    10
    1 9 6 10 6 7 9 3 9 2
    7 7 3 3 7 1 5 1 6 2

    Sample Output

    1
    0
    23
    54
    

    HINT


    Source

    TopCoder

    [ Top ] | [ Submit ] | [ Statistics ] | [ Standing ]