Oracle Prophecy Counts

View as PDF

Submit solution

Points: 14
Time limit: 2.0s
Memory limit: 64M

Authors:
Problem type
Allowed languages
C, C++, Java, Python

Oracle Prophecy Counts

In the Ancient Greece there are lots of Oracles. Each of the Oracles makes P prophecies everyday. Overtime there is variation in this. The Priest decides to take regular counts and writes these down on his tablets. This is what the entries look like.

...
35 1234 -2  
14 2345 +3  
...

The first entry indicates that on day 35, Oracle \(#1234's\) prophecy counts were 2 lower than it was when last measured. The next entry indicates that on day 14, Oracle \(#2345's\) prophecy count increased by 3 from when it was last measured. The Priest has only enough time to make at most one measurement on any given day. Unfortunately, he is a bit disorganized, and doesn't necessarily write down his measurements in chronological order.

To keep his Oracles motivated, Priese proudly displays on the wall of the Temple, the picture of whichever Oracle currently has the highest prophecy count (if several oracles tie for the highest count, he displays all of their pictures).

Please determine the number of days on which the Priest would have needed to change this display.

Note that the Priest has a very large number of Oracles, so although some of them are noted in his log book as changing their prophecy count , there are always plenty of other Oracles around whose prophecy count remains at P counts.

INPUT FORMAT

The first line of input contains the number of measurements N that the Priest makes, followed by P. Each of the next N lines contains one measurement, in the format above, specifying a day, the OracleID , and the change in her prophecy count since it was last measured (a nonzero integer).

SAMPLE INPUT:
4 10
7 3 +3
4 2 -1
9 3 -1
1 1 +2

OUTPUT FORMAT

Please output the total counts of days on which The Priest needs to adjust his temple display. This would be a single number. e.g. if he updates twice the answer is 2.
In the sample below Priest update the display on 3 separate days.

SAMPLE OUTPUT:
3

Constraints

1 \le P \le 10^9
1 \le N \le 100,000
1 \le day \le 10^6
1 \le OracleID \le 10^9

Test cases available here!


Comments

There are no comments at the moment.