아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Family Visits

시간 제한2초메모리 제한1024 MB

요약
날마다 생기는 어질러짐, 오후에 치울 수 있는 양, 가족이 방문하는 날이 주어질 때 방문하는 날마다 방이 깨끗하도록 청소하는 오후의 최소 횟수를 구한다.
난이도

보통10점 중 6점

유형
그리디, 누적 합, 정렬
정답자
아직 제출이 없습니다

문제

You are a college student living on your own. However, your doting family still likes to visit you, and they often stop by to check on your room at night before going to dinner. Your family will be worried if they find a mess in your room. Therefore you make an effort to ensure that they never see a mess in your room when visiting at night. You have some free time each afternoon that allows you to clean up, but the amount of free time varies each day due to prior commitments.

Luckily, your schedule is planned out well. You know exactly how big of a mess you will make each morning, how much mess you can clean each afternoon, and on which nights your family will stop by. Since you are lazy, you want to spend as few afternoons as possible cleaning such that your family will always see a room without any mess. You may assume that your room starts completely clean, and any mess that is not cleaned remains until it is cleaned.

입력

The first line of input contains two integers, nn and dd (1≤d≤n≤1,0001 \leq d \leq n \leq 1\\,000), where nn is the number of days in your schedule and dd is the number of days your family will visit.

Each of the next nn lines contains two integers mm and cc (0≤m,c≤1,0000 \le m,c \le 1\\,000). For each day, in order, mm is the amount of mess you make in the morning, and cc is the amount you can clean in the afternoon.

Each of the next dd lines contains a single integer vv (1≤v≤n1 \le v \le n). These are the days on which your family will visit, and they are listed in strictly increasing order.

출력

Output the smallest number of afternoons you have to spend cleaning to ensure your family will never see a mess. If it is not possible, output −1-1.

예제2

  1. 예제 1

    입력
    6 2
    1 2
    2 1
    1 4
    3 2
    3 6
    2 3
    3
    6
    
    예상 출력
    3
    
  2. 예제 2

    입력
    10 5
    12 10
    0 2
    7 1
    1 8
    3 4
    3 4
    2 3
    1 2
    10 1
    7 5
    2
    4
    5
    6
    8
    
    예상 출력
    7