Universal Cup Judging System

Universal Cup

時間限制: 1.5 s 記憶體限制: 512 MB 總分: 100
统计

נתונות לכם $n$ שלשות של מספרים שלמים $(a_i, b_i, c_i)$, כך שמתקיים $a_i < b_i < c_i$. עליכם לבחור זוג ערכים מכל שלשה וכך ליצור $n$ קטעים. עליכם לבחור את הזוגות כך שלכל שני קטעים שונים יהיה חיתוך באורך אפס. מצאו את הסכום המקסימלי האפשרי של אורכי הקטעים, או קבעו שאי אפשר לבחור קטעים המקיימים את התנאי.

קלט

השורה הראשונה מכילה מספר שלם אחד $n$ — מספר השלשות. $n$ השורות הבאות מכילות שלושה מספרים שלמים $a_i$, $b_i$ ו-$c_i$ — השלשה ה-$i$.

פלט

אם אי אפשר ליצור קטעים המקיימים את התנאי, הדפיסו -1. אחרת, הדפיסו את הסכום המקסימלי האפשרי של אורכי הקטעים.

מגבלות

$1 \le n \le 10^6$, $1 \le a_i < b_i < c_i \le 10^9$.

דוגמאות

קלט 1

4
1 2 3
2 3 5
7 8 9
4 7 8

פלט 1

7

קלט 2

3
1 2 4
1 2 4
1 2 4

פלט 2

-1

הערה

בדוגמה הראשונה, ישנן $n = 4$ שלשות: $(1, 2, 3)$, $(2, 3, 5)$, $(7, 8, 9)$ ו-$(4, 7, 8)$. פתרון אופטימלי אחד הוא: $(1, 2)$, $(2, 3)$, $(7, 9)$, $(4, 7)$. קטעים אלה מקיימים את התנאי שלכל שני קטעים שונים יש חיתוך באורך אפס. סכום אורכיהם הוא $(2 - 1) + (3 - 2) + (9 - 7) + (7 - 4) = 1 + 1 + 2 + 3 = 7$. בדוגמה השנייה, אי אפשר לבחור את הקטעים כך שיקיימו את התנאי.

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.