/ spv / 题库 /

Sunscreen

Sunscreen

Description

To avoid unsightly burns while tanning, each of the \(C (1 \le C \le 2.5\times10^3)\) cows must cover her hide with sunscreen when they're at the beach. Cow \(i\) has a minimum and maximum SPF rating \((1 \le \mathtt{minSPF}_i \le \mathtt{maxSPF}_i \le 10^3)\) that will work. If the SPF rating is too low, the cow suffers sunburn; if the SPF rating is too high, the cow doesn't tan at all........

The cows have a picnic basket with \(L (1 \le L \le 2.5\times10^3)\) bottles of sunscreen lotion, each bottle \(i\) with an SPF rating \(s_i\) \((1 ≤ \mathtt{SPF}_i ≤ 10^3)\). Lotion bottle \(i\) can cover \(c_i\) cows with lotion. A cow may lotion from only one bottle.

What is the maximum number of cows that can protect themselves while tanning given the available lotions?

Input

  • Line 1: Two space-separated integers: \(C\) and \(L\)
  • Lines \(2..C+1\): Line \(i\) describes cow i's lotion requires with two integers: \(\mathtt{minSPF}_i\) and \(\mathtt{maxSPF}_i\)
  • Lines \(C+2..C+L+1\): Line \(i+C+1\) describes a sunscreen lotion bottle \(i\) with space-separated integers: \(\mathtt{SPF}_i\) and \(c_i\)

Output

A single line with an integer that is the maximum number of cows that can be protected while tanning

Simplified

\(C\) 头奶牛在海滩边晒太阳,每头奶牛必须用防晒霜覆盖它的皮肤。第 \(i\) 头奶牛有一个最小和最大 SPF 值。如果 SPF 值太低,则奶牛会受到日光灼伤;如果 SPF 值太高,则牛奶无法进行日光浴。

奶牛们带了 \(L\) 瓶防晒霜乳液,第 \(i\) 瓶的 SPF 值是 \(s_i\) 。第 \(i\) 瓶防晒霜可以涂抹覆盖 \(c_i\) 头奶牛。一头牛奶只能用一瓶防晒霜涂抹。

对于给定的防晒霜乳液,最多可以有多少头奶牛能够在日光浴时避免被灼伤或无法进行日光浴?

Samples

Sample #1

Input

3 2
3 10
2 5
1 5
6 2
4 1

Output

2

Source

算法竞赛进阶指南 POJ

信息

ID
1024
难度
9
分类
(无)
标签
(无)
递交数
5
已通过
1
通过率
20%
被复制
1
上传者