RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 R03744

Bouquet

설명

After visiting Keukenhof, one of the world's largest flower gardens, Lieke became very fond of flowers, so she has decided to collect some tulips growing next to the road in order to build a beautiful bouquet. However, when collecting the flowers, she has to respect some rules due to the strict tulip protection laws in the Netherlands.

There are \(N\) tulips numbered from \(0\) to \(N-1\) growing in a line along the road, in order from left to right. The tulip protection law assigns two integers, \(l_i\) and \(r_i\), to tulip \(i\). In case tulip \(i\) is included in the bouquet, the \(l_i\) tulips immediately to the left of tulip \(i\) and the \(r_i\) tulips immediately to the right of tulip \(i\) cannot also be in the bouquet. Note that if there are fewer than \(l_i\) tulips to the left or fewer than \(r_i\) tulips to the right of tulip \(i\), then all tulips from that side are still excluded from the bouquet (overflows are allowed).

Lieke wonders what the maximum number of tulips she can pick is if she picks her flowers optimally. Help her build a beautiful bouquet by finding the answer to her question!

(An illustrative figure from the official statement is omitted here.)

제약
  • \(1 \leq N \leq 2 \cdot 10^5\).
  • \(0 \leq l_i, r_i \leq N\) for \(i = 0,1,\ldots, N-1\).

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group, you need to solve all test cases in the test group.

Group | Score | Limits 1 | 8 | \(l_i = r_i = l_j = r_j\) for all pairs (\(i, j\)) 2 | 16 | \(r_i = 0\) for all \(i\) 3 | 28 | \(N \leq 1000\) 4 | 18 | \(l_i, r_i \leq 2\) for all \(i\) 5 | 30 | No additional constraints

입력 형식

The first line of input contains a single integer \(N\), the number of tulips growing along the road.

The following \(N\) lines describe the information of the tulip protection law: the \(i\)th line contains two integers \(l_i\) and \(r_i\), representing the tulip protection constraints for tulip \(i\).

출력 형식

Output a single integer, the maximum number of tulips Lieke can pick while respecting the protection law.

서브태스크
서브태스크점수설명

Subtask 1

8점

None

Subtask 2

16점

None

Subtask 3

28점

None

Subtask 4

18점

None

Subtask 5

30점

None

예제 1
입력
3
0 3
1 0
1 0
출력
1
예제 2
입력
5
0 3
1 0
0 1
2 0
1 0
출력
3
예제 3
입력
7
0 0
0 0
1 0
1 0
2 0
3 0
2 0
출력
4
예제 4
입력
6
2 2
2 2
2 2
2 2
2 2
2 2
출력
2
예제 5
입력
7
0 2
2 0
1 1
2 2
0 0
0 1
0 1
출력
3
문제 정보

rip 작성

출처 EGOI 2024

평가 및 의견

Bouquet

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Bouquet

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8