Logo
(追記) (追記ここまで)

6034번 - Barn Allocation 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB24151368.421%

문제

Farmer John recently opened up a new barn and is now accepting stall allocation requests from the cows since some of the stalls have a better view of the pastures.

The barn comprises N (1 <= N <= 100,000) stalls conveniently numbered 1..N; stall i has capacity C_i cows (1 <= C_i <= 100,000). Cow i may request a contiguous interval of stalls (A_i, B_i) in which to roam (1 <= A_i <= N; A_i <= B_i <= N), i.e., the cow would like to wander among all the stalls in the range A_i..B_i (and the stalls must always have the capacity for her to wander).

Given M (1 <= M <= 100,000) stall requests, determine the maximum number of them that can be satisfied without exceeding stall capacities.

Consider both a barn with 5 stalls that have the capacities shown and a set cow requests:

Stall id: 1 2 3 4 5
 +---+---+---+---+---+
Capacity: | 1 | 3 | 2 | 1 | 3 | 
 +---+---+---+---+---+
Cow 1 XXXXXXXXXXX (1, 3)
Cow 2 XXXXXXXXXXXXXXX (2, 5)
Cow 3 XXXXXXX (2, 3)
Cow 4 XXXXXXX (4, 5)

FJ can't satisfy all four cows, since there are too many requests for stalls 3 and 4.

Noting that Cow 2 requests an interval that includes stalls 3 and 4, we test the hypothesis that cows 1, 3, and 4 can have their requested stalls. No capacity is exceeded, so the answer for this set of data is 3 -- three cows (1, 3, and 4) can have their requests satisfied.

입력

  • Line 1: Two space-separated integers: N and M
  • Lines 2..N+1: Line i+1 contains a single integer: C_i
  • Lines N+2..N+M+1: Line i+N+1 contains two integers: A_i and B_i

출력

  • Line 1: The maximum number of requests that can be satisfied

제한

예제 입력 1

5 4
1
3
2
1
3
1 3
2 5
2 3
4 5

예제 출력 1

3

힌트

출처

Olympiad > USA Computing Olympiad > 2009-2010 Season > USACO March 2010 Contest > Gold 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /