from heapq import * class Node(object): def __init__(self, l): super(Node, self).__init__() # Start, Finish and Weight self.s = l[0]; self.f = l[1]; self.w = l[2] def __lt__(self, o): return self.f < o.f N, M = map(int, raw_input().split()) A = []; heap = [] for m in xrange(M): A.append(Node(map(int, raw_input().split()))) A.sort(key = lambda x: x.s) maxi = 0; m = 0 for a in A: while len(heap)>0 and heap[0].f<a.s: m -= heappop(heap).w m += a.w if m>maxi: maxi = m heappush(heap, a) print maxi
Sample Input:
5 3 1 2 100 2 5 100 3 4 100
Sample Output:
200