Black Boxes

View as PDF

Submit solution

Points: 1
Time limit: 5.0s
Memory limit: 256M

Author:
Problem type

Problem Statement

You have a two-dimensional plane, initially the plane is white. On this two-dimensional plane you will perform n queries on this plane:

  • Each query is given l, r and h
  • Colour the rectangle (l, 0) to (r, h) At the end of all n queries, determine the total area which is black.

Input Format

Your first line will contain a single integer n. Your next n lines will contain three integers each, representing l, r and h respectively.

Output Format

Output the total number of area that is coloured black after performing all queries.

Constraints

  • 1 \leq n \leq 10^5
  • 0 \leq l \leq r \leq 10^9
  • 1 \leq h \leq 10^9

Sample Cases

Input 1
3
0 1 1
0 3 3
2 4 2
Output 1
11
Input 2
2
0 100000 100000
1 99999 100001
Output 2
10000099998

Template

n = int(input())
rectangles = [tuple(map(int, input().split())) for _ in range(n)]

# print your output

Comments

There are no comments at the moment.