@@ -0,0 +1,2517 @@
+package org.pilgrim.hiredintech;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Map.Entry;%0Aimport java.util.Scanner;%0Aimport java.util.Set;%0Aimport java.util.TreeMap;%0A%0Apublic class GridlandMetro%0A%7B%0A%0A    public static class Track implements Comparable%3CTrack%3E%0A    %7B%0A        long r;%0A        long c1;%0A        long c2;%0A%0A        public boolean isInside(int c)%0A        %7B%0A            return c %3E= c1 && c %3C= c2;%0A        %7D%0A%0A        public long length()%0A        %7B%0A            return Math.abs(c2 - c1 + 1);%0A        %7D%0A%0A        public int compareTo(Track o)%0A        %7B%0A            return Long.compare(c1, o.c1);%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args)%0A    %7B%0A        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */%0A        Scanner sc = new Scanner(System.in);%0A        long n = sc.nextLong();%0A        long m = sc.nextLong();%0A        long k = sc.nextLong();%0A%0A        Map%3CLong, TreeMap%3CLong, Track%3E%3E map = new HashMap%3C%3E();%0A        for (long i = 0; i %3C k; i++)%0A        %7B%0A            long r = sc.nextLong() - 1L;%0A%0A            Track track = new Track();%0A            track.r = r;%0A            track.c1 = sc.nextLong() - 1L;%0A            track.c2 = sc.nextLong() - 1L;%0A%0A            Track prevTrack = null;%0A            TreeMap%3CLong, Track%3E list = map.get(r);%0A            if (null == list)%0A            %7B%0A                list = new TreeMap%3C%3E();%0A                map.put(r, list);%0A            %7D%0A            else%0A            %7B%0A                Map.Entry%3CLong, Track%3E entry = list.floorEntry(track.c1);%0A                if (null != entry)%0A                %7B%0A                    prevTrack = entry.getValue();%0A                %7D%0A            %7D%0A%0A            if (null != prevTrack && prevTrack.c2 %3E= track.c1)%0A            %7B%0A                prevTrack.c2 = Math.max(track.c2, prevTrack.c2);%0A            %7D%0A            else%0A            %7B%0A                list.put(track.c1, track);%0A            %7D%0A        %7D%0A        sc.close();%0A%0A        long lampposts = 0;%0A        for (long i = 0; i %3C n; i++)%0A        %7B%0A            TreeMap%3CLong, Track%3E list = map.get(i);%0A            lampposts += m;%0A            if (null == list)%0A            %7B%0A                continue;%0A            %7D%0A            Set%3CEntry%3CLong, Track%3E%3E entrySet = list.entrySet();%0A            for (Entry%3CLong, Track%3E entry : entrySet)%0A            %7B%0A                Track track = entry.getValue();%0A                lampposts -= track.length();%0A            %7D%0A        %7D%0A%0A        System.out.println(lampposts);%0A%0A    %7D%0A%7D%0A

add first version of Gridland metro