Logo
(追記) (追記ここまで)

33060번 - Deforestation 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB158988370.339%

문제

Farmer John is expanding his farm! He has identified the perfect location in the Red-Black Forest, which consists of $N$ trees (1ドル \le N \le 10^5$) on a number line, with the $i$-th tree at position $x_i$ ($-10^9 \le x_i \le 10^9$).

Environmental protection laws restrict which trees Farmer John can cut down to make space for his farm. There are $K$ restrictions (1ドル \leq K \leq 10^5$) specifying that there must always be at least $t_i$ trees (1ドル \leq t_i \leq N$) in the line segment $[l_i, r_i],ドル including the endpoints ($-10^9 \le l_i \leq r_i \le 10^9$). It is guaranteed that the Red-Black Forest initially satisfies these restrictions.

Farmer John wants to make his farm as big as possible. Please help him compute the maximum number of trees he can cut down while still satisfying all the restrictions!

입력

Each input consists of $T$ (1ドル \le T \le 10$) independent test cases. It is guaranteed that the sums of all $N$ and of all $K$ within an input each do not exceed 3ドル \cdot 10^5$.

The first line of input contains $T$. Each test case is then formatted as follows:

  • The first line contains integers $N$ and $K$.
  • The next line contains the $N$ integers $x_1, \dots, x_N$.
  • Each of the next $K$ lines contains three space-separated integers: $l_i,ドル $r_i$ and $t_i$.

출력

For each test case, output a single line with an integer denoting the maximum number of trees Farmer John can cut down.

제한

예제 입력 1

3
7 1
8 4 10 1 2 6 7
2 9 3
7 2
8 4 10 1 2 6 7
2 9 3
1 10 1
7 2
8 4 10 1 2 6 7
2 9 3
1 10 4

예제 출력 1

4
4
3

힌트

For the first test case, Farmer John can cut down the first 4ドル$ trees, leaving trees at $x_i = 2, 6, 7$ to satisfy the restriction.

For the second test case, the additional restriction does not affect which trees Farmer John can cut down, so he can cut down the same trees and satisfy both restrictions.

For the third test case, Farmer John can only cut down at most 3ドル$ trees because there are initially 7ドル$ trees but the second restriction requires him to leave at least 4ドル$ trees uncut.

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2024 December Contest > Silver 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /