1966: [USACO 2022 US Open Contest Gold] Problem 1. Apple Catching

文件提交:无需freopen 内存限制:256 MB 时间限制:2.000 S
评测方式:普通裁判 命题人:
提交:5 解决:1

题目描述

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 N (1N2105), the number of times apples hit the number line or FJ's cows appear.

The next N lines each contain four integers qitixi, and ni (qi{1,2},0ti109,0xi109,1ni103)

  • If qi=1, this means that ni of FJ's cows arrive on the number line at time ti at location xi.
  • If qi=2, this means that ni apples will hit the number line at time ti at location xi.

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

输出

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

样例输入

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

样例输出

10

提示

In this example, none of the  apples that land at time t=5 may be caught. Here is a way for apples to be caught:

  • All six of FJ's cows that arrive at time t=4 catch one of the apples that land at time t=8.
  • One of FJ's cows that arrive at time t=2 catches one of the apples that land at time t=8.
  • Three of the remaining cows that arrive at time t=2 catch one of the apples that land at time t=6.

SAMPLE INPUT:

5

2 5 10 100

2 6 0 3

2 8 11 7

1 2 4 5

1 4 7 6

SAMPLE OUTPUT:

9

Here again, none of the apples that land at time t=5 may be caught. Furthermore, none of the cows that arrive at time t=2 may catch any of the apples that land at time t=8. Here is a way for 
 apples to be caught:

  • All six of FJ's cows that arrive at time t=4 catch one of the apples that land at time t=8.
  • Three of the remaining cows that arrive at time t=2 catch one of the apples that land at time t=6.

来源/分类