12205 - Happy Telephones

All about problems in Volume 122. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

12205 - Happy Telephones

Post by uDebug » 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
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

piyukr
New poster
Posts: 17
Joined: Sun Jan 26, 2014 10:35 am

Re: 12205 - Happy Telephones

Post by piyukr » 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);
	    }
	}
    }
}

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 12205 - Happy Telephones

Post by uDebug » 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.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

piyukr
New poster
Posts: 17
Joined: Sun Jan 26, 2014 10:35 am

Re: 12205 - Happy Telephones

Post by piyukr » 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.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 12205 - Happy Telephones

Post by uDebug » 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.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 122 (12200-12299)”