시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 3240 715 526 23.151%

문제

세계적인 도둑 상덕이는 보석점을 털기로 결심했다.

상덕이가 털 보석점에는 보석이 총 N개 있다. 각 보석은 무게 Mi와 가격 Vi를 가지고 있다. 상덕이는 가방을 K개 가지고 있고, 각 가방에 담을 수 있는 최대 무게는 Ci이다. 가방에는 최대 한 개의 보석만 넣을 수 있다.

상덕이가 훔칠 수 있는 보석의 최대 가격을 구하는 프로그램을 작성하시오.

입력

첫째 줄에 N과 K가 주어진다. (1 ≤ N, K ≤ 300,000)

다음 N개 줄에는 각 보석의 정보 Mi와 Vi가 주어진다. (0 ≤ Mi, Vi ≤ 1,000,000)

다음 K개 줄에는 가방에 담을 수 있는 최대 무게 Ci가 주어진다. (1 ≤ Ci ≤ 100,000,000)

모든 숫자는 양의 정수이다.

출력

첫째 줄에 상덕이가 훔칠 수 있는 보석 가격의 합의 최댓값을 출력한다.

예제 입력 1

3 2
1 65
5 23
2 99
10
2

예제 출력 1

164

힌트

첫 번째 보석을 두 번째 가방에, 세 번째 보석을 첫 번째 가방에 넣으면 된다.

W3sicHJvYmxlbV9pZCI6IjEyMDIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJjZjRcdWMxMWQgXHViM2M0XHViNDUxIiwiZGVzY3JpcHRpb24iOiI8cD5cdWMxMzhcdWFjYzRcdWM4MDFcdWM3NzggXHViM2M0XHViNDUxIFx1YzBjMVx1YjM1NVx1Yzc3NFx1YjI5NCBcdWJjZjRcdWMxMWRcdWM4MTBcdWM3NDQgXHVkMTM4XHVhZTMwXHViODVjIFx1YWNiMFx1YzJlY1x1ZDU4OFx1YjJlNC48XC9wPlxyXG5cclxuPHA+XHVjMGMxXHViMzU1XHVjNzc0XHVhYzAwIFx1ZDEzOCBcdWJjZjRcdWMxMWRcdWM4MTBcdWM1ZDBcdWIyOTQgXHViY2Y0XHVjMTFkXHVjNzc0IFx1Y2QxZCBOXHVhYz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BvdXRwdXQgbXVzdCBjb250YWluIHRoZSBtYXhpbXVtIHBvc3NpYmxlIHRvdGFsIGpld2VsbGVyeSB2YWx1ZS4mbmJzcDs8XC9wPlxyXG5cclxuPHA+Jm5ic3A7PFwvcD5cclxuIiwiaGludCI6IjxwPk1pcmtvIHN0b3JlcyB0aGUgZmlyc3QgcGllY2Ugb2YgamV3ZWxsZXJ5IGludG8gdGhlIHNlY29uZCBiYWcgYW5kIHRoZSB0aGlyZCBwaWVjZSBpbnRvIHRoZSBmaXJzdCBiYWcuJm5ic3A7PFwvcD5cclxuIiwib3JpZ2luYWwiOiIxIiwicHJvYmxlbV9sYW5nX2NvZGUiOiJcdWM2MDFcdWM1YjQifV0=

출처

Contest > Croatian Open Competition in Informatics > COCI 2013/2014 > Contest #1 4번

  • 문제를 번역한 사람: baekjoon
  • 잘못된 조건을 찾은 사람: eeight