1 / 3
Jan 2023

It’s not my code, so I won’t post it here, but it uses BufferedReader. To read a line with 1 integer it does:

int x = Integer.parseInt(reader.readLine());

To read a line with 2 integers it does:

StringTokenizer st = new StringTokenizer(reader.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());

After that it does some simple O(n log n) computations and prints the answer. But it keeps getting TLE. Is this problem not solvable in Java? Is there a faster input method that needs to be usued?

  • created

    Jan '23
  • last reply

    Feb '23
  • 2

    replies

  • 582

    views

  • 3

    users

  • 1

    link

Using BufferedReader and readLine was sufficient for me to get accepted (as an extra optimization I packed the parsed input into a flat long[] array, to avoid an additional level of indirection).

11 days later

Yes. To see Java solutions for this problem BUSYMAN Java Ranks14

For any problem, click on ranks. At the URL add “/lang=Java”, and you can see the Java solutions for that problem.