Logo
(追記) (追記ここまで)

19153번 - Jordan 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB123281622.535%

문제

Michael likes to spend time with numbers... wait a minute, the statement should have a story about a mathematician!

Camille likes to spend time with numbers. This morning, he drew on a whiteboard an infinite number line and marked on it a finite set of distinct points with real coordinates. Also, for each of these points he chose some real non-negative value, named it weight of the point, and started to have fun. $N$ times Camille selected a segment $[l_i; r_i]$ on the number line and counted the sum of weights of all points lying inside this segment. In case you forget, point $x$ lies inside the segment $[l; r]$ if $l \leq x \leq r$. He wrote all these calculations down to his notebook and left the room for a lunch.

Henri likes to tease Camille, and that was not an opportunity he could miss. While Camille was enjoying frog legs and young Bordeaux, Henri took a sponge and cleared the board completely. When the prank revealed, Camille's disappointment was out of description!

You accidentally witnessed this crime and now feel a little ashamed for not preventing it. Moreover, you still remember nice days spent together with Bernhard and Camille, when you were freshmen, so you decided to help him. Given his records, calculate 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.

입력

The first line of the input contains a single integer $N$ --- the number of records in Camille's notebook (1ドル \le N \le 1000$).

Next $N$ lines describe the calculations he performed. Each of them contains three integers. First two of them are $l_i$ and $r_i$ --- borders of the segment, the last one is the sum of weights of all points lying inside this segment $s_i$ ($-10^9 \le l_i \le r_i \le 10^9,ドル 0ドル \le s_i \le 10^9$).

출력

Print the minimum and maximum possible total weight of all points drawn by Camille. If the data is inconsistent print two numbers $-1$ instead.

제한

예제 입력 1

2
1 2 1
2 3 1

예제 출력 1

1 2

예제 입력 2

2
1 2 1
1 2 2

예제 출력 2

-1 -1

힌트

In the first example, one can obtain the total weight 1ドル$ by having just one point with coordinate $x = 2$ and weight 1. Also, one can obtain the total weight 2ドル$ by having two points with weights 1 and coordinates $x = 1.5$ and $x = 2.5$ respectively.

In the second example, the input data is obviously inconsistent.

출처

Camp > Petrozavodsk Programming Camp > Winter 2015 > Day 4: Moscow SU Tapirs Contest 2 J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /