Universal Cup Judging System

Universal Cup

Time Limit: 1.5 s Memory Limit: 512 MB Total points: 100
Statistics

تُعطى لك $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.