#P10377. [GESP202403 六级] 好斗的牛

[GESP202403 六级] 好斗的牛

Background

Related multiple-choice / true-false problem: https://ti.luogu.com.cn/problemset/1146.

Problem Description

You have 10910^9 cowsheds lined up from left to right. You want to place nn cows into the cowsheds. The troublesome part is that your cows are very aggressive: if there are other cows nearby, they will get restless and start trouble. For cow ii, its attack range is (ai,bi)(a_i, b_i), which means that if there is any other cow within aia_i cowsheds to its left or within bib_i cowsheds to its right, it will start trouble.

You want to keep a continuous segment of cowsheds and sell all the other cowsheds. What is the minimum number of cowsheds you must keep to ensure that there exists at least one way to place all nn cows into the remaining cowsheds such that no cow will start trouble?

Input Format

The first line contains a positive integer nn.
The second line contains nn positive integers a1,a2,ana_1, a_2, \dots a_n.
The third line contains nn positive integers b1,b2,bnb_1, b_2, \dots b_n.

Output Format

Output one line with one integer representing the answer.

2
1 2
1 2

4
3
1 2 3
3 2 1

7

Hint

Sample 1 Explanation

Keep cowsheds 1,2,3,41, 2, 3, 4, and place two cows in cowsheds 11 and 44, respectively.

Constraints

  • For 20%20\% of the testdata, n=2n = 2 is guaranteed.
  • For another 20%20\% of the testdata, n=3n = 3 is guaranteed.
  • For 80%80\% of the testdata, n8n \leq 8 is guaranteed.
  • For all testdata, 1n91 \leq n \leq 9, 1ai,bi1031 \leq a_i, b_i \leq 10^3 are guaranteed.

Translated by ChatGPT 5