Page 1 of 1

### 12205 - Happy Telephones

Posted: Thu Jan 30, 2014 11:51 am
Here's some input / output that I found useful during testing / debugging.

Input:

Code: Select all

``````9 14
3 4 2 5
1 2 9 1
6 5 9 1
7 6 5 5
7 2 1 1
2 9 22 24
1 8 0 1
23 44 3 97
11 10 85 14
9 1
10 1
10 2
9 2
0 1
0 23
0 3
0 4
3 97
10 20
95 5
90 10
99 2
98 2
0 0
``````
AC Output:

Code: Select all

``````4
1
1
4
1
8
3
4
7
2
2
2
1
2
``````

### Re: 12205 - Happy Telephones

Posted: Tue Feb 04, 2014 10:56 am
My answers match the expected ones but I get TLE. Could you help me optimize it?

Code: Select all

``````import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String[] s = br.readLine().split(" ");
int a = Integer.parseInt(s[0]);
int b = Integer.parseInt(s[1]);
if (a == 0 && b == 0) {
break;
}
int[] start = new int[a];
int[] duration = new int[a];
int[] end = new int[a];
int x = 0, y = 1;
while (x < a) {
s = br.readLine().split(" +");
start[x] = Integer.parseInt(s[2]);
duration[x] = Integer.parseInt(s[3]);
end[x] = start[x] + duration[x];
x++;
}
int count = 0;
while (y <= b) {
count = 0;
s = br.readLine().split(" +");
for (int i = 0; i < a; i++) {
if (Integer.parseInt(s[1]) != 0) {
if (Integer.parseInt(s[0]) < end[i] && (Integer.parseInt(s[0]) + Integer.parseInt(s[1])) > start[i]) {
count++;
}
}
}
y++;
System.out.println(count);
}
}
}
}
``````

### Re: 12205 - Happy Telephones

Posted: Tue Feb 04, 2014 11:24 am
piyukr,

It's probably not a good idea to double-post. It looks like felix_halim answered your questions in detail over on uHunt.

### Re: 12205 - Happy Telephones

Posted: Tue Feb 04, 2014 11:56 am
I have a had a few times when my queries slipped unnoticed on the chat.I didn't get any reply for sometime today so I thought may be it was better to post the doubt here.

### Re: 12205 - Happy Telephones

Posted: Tue Feb 04, 2014 12:55 pm
piyukr,

It's good news that you figured this out.

It might be a good idea to remove this code now (since it's mostly AC) and perhaps share what the issue you had was - and how you went about solving it. This way, people reading this thread can benefit from your experience / input.