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

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

Apple Catching

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

요약
소들이 수직선 위에 도착해 초속 1로 움직여 사과 하나씩을 잡을 수 있을 때, 잡을 수 있는 사과 수의 최댓값을 구합니다.
난이도

보통10점 중 7점

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

문제

It's raining apples! At certain points in time, some number of apples will hit the number line. At certain points in time, some of Farmer John's cows will arrive on the number line and start catching apples.

If an apple hits the number line without a cow to catch it, it is lost forever. If a cow and an apple arrive at the same time, the cow catches it. Each cow can travel one unit per second. Once a cow catches a single apple, she exits the number line.

If FJ's cows collaborate optimally, how many apples can they catch in total?

입력

The first line contains NN (1≤N≤2⋅1051\le N\le 2\cdot 10^5), the number of times apples hit the number line or FJ's cows appear.

The next NN lines each contain four integers q_iq\_i, t_it\_i, x_ix\_i, and n_in\_i (q_i∈1,2,0≤t_i≤109,0≤x_i≤109,1≤n_i≤103q\_i\in \\{1,2\\}, 0\le t\_i\le 10^9, 0\le x\_i\le 10^9, 1\le n\_i\le 10^3).

 

  • If q_i=1q\_i=1, this means that n_in\_i of FJ's cows arrive on the number line at time t_it\_i at location x_ix\_i.
  • If q_i=2q\_i=2, this means that n_in\_i apples will hit the number line at time t_it\_i at location x_ix\_i.

It is guaranteed that all of the ordered pairs (t_i,x_i)(t\_i,x\_i) are distinct.

출력

The maximum number of apples FJ's cows may collectively catch.

예제2

  1. 예제 1

    입력
    5
    2 5 10 100
    2 6 0 3
    2 8 10 7
    1 2 4 5
    1 4 7 6
    
    예상 출력
    10
    
  2. 예제 2

    입력
    5
    2 5 10 100
    2 6 0 3
    2 8 11 7
    1 2 4 5
    1 4 7 6
    
    예상 출력
    9