Jordan
Time limit1sMemory limit512 MB
Given N segments and the weight sum inside each, find the minimum and maximum possible total weight of all points, or -1 -1 if the records conflict.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Intervals, Prefix sum
- Solved
- No attempts yet
Statement
Camille likes to spend time with numbers. This morning, he drew an infinite number line on a whiteboard and marked on it a finite set of distinct points with real coordinates. For each point, he chose a non-negative real value and called it the weight of the point. Then he selected a segment on the number line times and counted the sum of weights of all points lying inside that segment. A point lies inside the segment if . He wrote all these calculations in his notebook and left the room for lunch.
Henri likes to tease Camille, and he could not pass up this chance. While Camille was enjoying frog legs and young Bordeaux, Henri took a sponge and erased the whole board. When the prank was revealed, Camille's disappointment was beyond words.
You accidentally witnessed this prank and feel a little ashamed for not stopping it. You also remember the good days you spent with Bernhard and Camille when you were freshmen, so you decided to help him. Given his records, find the minimum and maximum possible sum of weights of all the points. Assume that every marked point belongs to at least one segment selected by Camille.
Input
The first line contains a single integer , the number of records in Camille's notebook ().
Each of the next lines contains three integers , , and . Here and are the borders of the segment, and is the sum of weights of the points lying inside it.
(, )
Output
Print the minimum and the maximum possible total weight of all the points. If the records are inconsistent, print two numbers instead.
Notes
In the first case, a single point at with weight 1 gives the total weight 1. Two points with weight 1 at and give the total weight 2.
In the second case, the input is obviously inconsistent.