I am working on the same task.I am pasting mycode. Its show runtime error when i am trying to run for large input like 1 billion (i.e. k=10^9). Could you please help me with this?
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.StringTokenizer;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
static Long counter = (long)0;
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader ob1= new BufferedReader(new InputStreamReader(System.in));
int user_choice= Integer.parseInt(ob1.readLine());
int flag=0;
while(user_choice!=0)
{
user_choice--;
StringTokenizer obj;
Long n,k;
obj=new StringTokenizer(ob1.readLine());
n=Long.parseLong(obj.nextToken());
k=Long.parseLong(obj.nextToken());
Hashtable<Long, Long> hash= new Hashtable<Long, Long>();
while(n!=0)
{
StringTokenizer obj1;
Long start,comp;
Long finish;
obj1=new StringTokenizer(ob1.readLine());
start=Long.parseLong(obj1.nextToken());
finish=Long.parseLong(obj1.nextToken());
comp=Long.parseLong(obj1.nextToken());
if(flag==0)
{
for(int i=1;i<=k;i++)
{
hash.put((long)i,(long)0);
}
}
Long finish1;
finish1=hash.get(comp);
if(finish1==0)
{
hash.put(comp,finish);
counter++;
}
else if(finish1<=start)
{
counter++;
hash.put(comp,finish);
}
n--;
flag=1;
}
flag=0;
System.out.println(counter);
counter=(long)0;
/* for(int i=1;i<=k;i++)
System.out.println(hash.get((long)i) +" "+i );*/
}
}
}
Input :
2
3 300000
1 3 1
4 6 2
7 10 3
3 10000000
1 3 1
4 6 2
7 10 3
Output:
Runtime error time: 0.09 memory: 380160 signal:-1
3