#582
Unrated
Apple Catching
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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 (1N21051\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 qiq_i, tit_i, xix_i, and nin_i (qi{1,2},0ti109,0xi109,1ni103q_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 qi=1q_i=1, this means that nin_i of FJ's cows arrive on the number line at time tit_i at location xix_i. If qi=2q_i=2, this means that nin_i apples will hit the number line at time tit_i at location xix_i.

It is guaranteed that all of the ordered pairs (ti,xi)(t_i,x_i) are distinct.

출력

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

예제 입력 1

5
2 5 10 100
2 6 0 3
2 8 10 7
1 2 4 5
1 4 7 6

예제 출력 1

10

예제 입력 2

5
2 5 10 100
2 6 0 3
2 8 11 7
1 2 4 5
1 4 7 6

예제 출력 2

9
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.