포럼
문제 ICPC00365

M. Museum Visit

설명

Every day is different in the Groninger Museum. Some days are nice, peaceful and quiet, and you can spend all day looking at the beautiful paintings, sculptures, and other artworks. Other days are busier, when weekends or public holidays fill the museum with hasty visitors, increased prices and screaming children. This discomfort varies a lot: some busy days are better because of extra studentenkorting (student discount) and some of the quiet days get worse because of earthquake risks.

The museum also regularly hosts special limited-time exhibitions, such as those on the local football club FC Groningen, the Martinitoren, or the eierbal (a local delicacy). These exhibitions can be very irregular: some last for weeks, some last only a day, and there may be multiple exhibitions on the same day.

As a proud Grunneger, you want to visit each exhibition at least once. Luckily, you are subscribed to the newsletter so you know the start and end days of all the exhibitions in advance. Additionally, since you are a regular visitor at the museum, you have observed all the crowd and earthquake patterns, so you know exactly how much discomfort you will receive when you visit the museum on any specific day.

On which days should you visit the museum in order to minimize your total discomfort while still seeing all exhibitions that are planned in the foreseeable future? As an example, consider the first sample case. To minimize your total discomfort, you should visit the first two exhibitions on the second day and the last exhibition on the fourth or fifth day.

제약
입력 형식

The input consists of:
- One line with two integers \(n\) and \(m\) (\(1\leq n,m\leq 2\cdot10^5\)), the number of days in the foreseeable future and the number of exhibitions planned in those days.
- One line with \(n\) integers \(c\) (\(1\leq c\leq 10^9\)), describing for each day the discomfort you will receive when you visit the museum.
- \(m\) lines, each with two integers \(s\) and \(e\) (\(1\leq s\leq e\leq n\)), describing the start and end day of an exhibition. The start and end days are inclusive: the exhibition can be visited on day \(s\), day \(e\), and any day in between.

출력 형식

Output the minimum total discomfort you will receive when visiting all exhibitions of the Groninger Museum.

예제 1
입력
5 3
1 1 3 1 1
1 3
2 3
3 5
출력
2
예제 2
입력
6 3
1 2 4 4 2 1
1 4
2 5
3 6
출력
3
예제 3
입력
11 2
3 1 4 1 5 9 2 6 5 3 5
5 10
1 1
출력
5
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC BAPC 2024

평가 및 의견

M. Museum Visit

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

Log in to rate problems.

개별 의견

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

풀이 제출

M. Museum Visit

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