QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 256 MB 총점: 100

#23867. תאורת קישוט

통계

תיאור הבעיה

בבעלותו של מר JOI יש $N$ עצים בשטח ביתו. עצים אלה עומדים בשורה אחת וממוספרים לפי הסדר במספרים שלמים מ-$1$ עד $N$.

בחורף הזה החליט מר JOI לבחור כמה עצים ולקשט אותם בתאורה. לתאורה מוגדר ערך הנקרא יופי. היופי המתקבל מקישוט עץ $i$ בתאורה הוא $A_i$.

מר JOI שם לב שאם יקשט בתאורה את שניהם מבין $2$ עצים הקרובים מדי זה לזה, האור עלול להיות מסנוור מדי. באופן ספציפי, עבור $j = 1, 2, \dots, M$, התברר שאין לקשט בתאורה $2$ עצים או יותר מבין העצים $L_j$, $L_j + 1$, $\dots$, $R_j$.

מצא את הערך המקסימלי של סכום היופי כאשר מקשטים את העצים בתאורה בהתאם לתנאי זה.

אילוצים

  • $1 \le N \le 200000 (= 2 \times 10^5)$
  • $1 \le M \le 200000 (= 2 \times 10^5)$
  • $1 \le A_i \le 1000000000 (= 10^9)$ ($1 \le i \le N$)
  • $1 \le L_j \le R_j \le N$ ($1 \le j \le M$)

קלט / פלט

קלט
הקלט ניתן מהקלט הסטנדרטי בפורמט הבא:
$N$ $M$
$A_1$ $A_2$ $\dots$ $A_N$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_M$ $R_M$

פלט
הדפס בשורה $1$ את הערך המקסימלי של סכום היופי של התאורה.

תתי-משימות

  1. ($10$ נקודות) $N \le 16$, $M \le 16$
  2. ($30$ נקודות) $N \le 300$, $M \le 300$
  3. ($30$ נקודות) $N \le 4000$, $M \le 4000$
  4. ($30$ נקודות) אין הגבלות נוספות.

דוגמאות קלט / פלט

קלט לדוגמה 1

4 1
1 2 3 8
2 4

פלט לדוגמה 1

9

בקלט לדוגמה זה, אם מקשטים בתאורה את העצים $1$, $4$, סכום היופי הוא $9$, וזהו הערך המקסימלי. מכיוון ש-$L_1 = 2$, $R_1 = 4$, לא ניתן לקשט בתאורה $2$ עצים או יותר מבין העצים $2$, $3$, $4$. שים לב שלמשל לא ניתן לקשט את העצים $1$, $2$, $4$.


קלט לדוגמה 2

5 2
2 3 9 5 6
1 3
2 4

פלט לדוגמה 2

15

קלט לדוגמה 3

20 10
870851814 594414687 615919461 65033245 460143082 617460823 881870957 126041265 623075703 34130727 27054628 853567651 483228744 491145755 220689940 148007930 229257101 790404982 612186806 281076231
15 19
20 20
12 13
1 4
19 19
9 13
3 6
9 12
16 16
18 19

פלט לדוגמה 3

4912419478

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.