CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » November Long Contest 2011 » The Postal Service

The Postal Service

Problem code: POSTAL

  • All Submissions

All submissions for this problem are available.

The Chef is on vacation in the beautiful country of Chefville. The island is a narrow strip of land running from north to south. A single road from north to south connects all the villages in the country. There, he observed, the postal services works in a very curious way.

There is a postman for every village. In the morning, say postman A, starts traveling to the North, disbursing all the mails on the way. When he meets another postman coming from the opposite direction on the way, say B, A hands over all the mails to B which are to be delivered to addresses that lie in the North and vice versa for B. Then both turn back and start traveling in the opposite directions. So, now A travels to the South and when he meets another postman on the way, the same thing happens again. This keep on till the duty hours of the day finishes and they don't loose any time in the swapping and turning back. All postmen travel at the same speed of 1 m/s always and they arbitrarily choose their direction to start with in the morning.

Now, at any given time of the day, the Chef wants to know the position of any given postman and the number of times he has met another postman till that time (including this moment of time).

Input

The road can be considered to stretch infinitely in both the directions for this problem. The first line contains the total number of test cases (<= 10). Each of the case begins with N (0 < N <= 500) on a separate line, the total number of villages in Chefville. The next line contain N distinct integers separated by space which are the positions (between 0 and 1000000000, in meters including those, 0 being the position of a northern point on the strip) in increasing order of the N villages on the road. The next line the initial directions of the corresponding postmen of the villages as N integers which are either 0 or 1. 0 means North and 1 South. Then comes the total number of queries Q (<= 1000) for this test case on separate line. The next Q lines contain two integers, first the postman number I (0 <= I < N) and then the time T (<= 1000000000 in seconds).

Output

For every query of a test case, you have to output the position of the postman number I at time T and the number times he has met another postman till then, on the same line separated by a space.

Example

Input:
1
5
1 24 28 34 94 
0 1 0 0 0 
2
2 11
0 9

Output:
23 2
-8 0


Author: nomind
Date Added: 11-09-2011
Time Limit: 12 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Do you consider it fair to

wazzzup @ 1 Nov 2011 07:14 PM
Do you consider it fair to change the problem during the competition? The Postal service problem initially had max 100 villages and the max distance was a 1000 meters, this has now changed to 500 villages with a max distance of 1000000000 meters. This is no trivial change, the solution will be very different.

@admin . how will two postman

maverick_dp @ 1 Nov 2011 08:01 PM
@admin . how will two postman meet if they are at odd distance away and travelling in opposite directions. ex. one starts at 1 and another at 4 in opposite directions . where do they meet?

They will meet at coordinate

anirban_adm @ 1 Nov 2011 10:52 PM
They will meet at coordinate 2.5

@wazzup - This is due to a

anirban_adm @ 1 Nov 2011 10:56 PM
@wazzup - This is due to a technical problem with the platform. We have taken it on high priority and will be fixed soon so, this things doesn't repeat

@wazzup - There was a

admin @ 1 Nov 2011 11:36 PM

@wazzup - There was a discrepancy with the problem statement due to a glitch in our systems. The constraints of the problem were always the way you see them now, it's just that they were written wrong. What you see now is how the problem was intended by the problem setter all along, and our systems hadn't displayed it correctly. Changes were made so that the problem statement is in accord with the problem.
We are sorry for the initial misleading information, and our efforts are focused on eliminating such events from occurring.

@admin - if the final

ankit2311 @ 2 Nov 2011 10:11 AM
@admin - if the final co-ordinate of the postman comes out to be a non-integer, is there any specification regarding the precision of the answer??

@ maverick_dp Consider P1

nehaljwani @ 2 Nov 2011 10:29 AM
@ maverick_dp Consider P1 with dir:1 and P2 with dir:0 t=0 P1:1 P2:4 t=1 P1:2 P2:3 t=1.5 P1:2.5 P2:2.5.... Now they Swap (Remember, Speed=1m/s) t=2 P1:2 P2:3 t=3 P1:1 P2:4 Co-Ordinate can never be non-integer at integral multiple of time.

What will happen is a person

csimstu @ 2 Nov 2011 01:13 PM
What will happen is a person move out of [0, 1000000000] ?

plz explane 0,9 gives -8 and

goelrinku @ 2 Nov 2011 04:10 PM
plz explane 0,9 gives -8 and 0 how?

@csimstu - Only input

anirban_adm @ 2 Nov 2011 05:40 PM
@csimstu - Only input coordinates will be in the range. The actual coordinates of postmen at any point of time can go beyond that range.

almost same question has

gurpreet_09 @ 3 Nov 2011 08:00 PM
almost same question has already appeared in one of the competitions.

If I understand right both

theicebreaker @ 5 Nov 2011 11:05 PM
If I understand right both time and positions of postmen can be non integer values.

@anirban_adm: Can we safely

tarun_joshi01 @ 6 Nov 2011 09:17 AM
@anirban_adm: Can we safely assume that the postman at either ends turn back as soon as they reach their respective villages and not continue to go further (since practically they have delivered the messages to their respective village and should go back to pick up new ones rather then continuing in the original direction)?

No its clear that they keep

theicebreaker @ 6 Nov 2011 10:58 AM
No its clear that they keep going until they meet someone and then they turn back. Like in the testcase the postmen at 1 keeps going north as their is no one to his north to make him turn back.

what would be the answer for

svm11 @ 6 Nov 2011 02:09 PM
what would be the answer for the query "the number times he has met another postman till then" for every postman if n = 3 initial coordinates --> 1, 2, 3 initial directions --> 1 1 0 time = 1

Never mind my last

svm11 @ 6 Nov 2011 03:41 PM
Never mind my last comment..got AC!

Can somebody give some

cricketer @ 6 Nov 2011 07:42 PM
Can somebody give some boundary test cases????

mine is now coming

cricketer @ 7 Nov 2011 02:13 AM
mine is now coming TLE...........i don't know why...........i have run it on my computer with 500 n's and it is running.....................i have simply simulate the problem......... plz give me some advice

@cricketer maybe you are

dudechandan123 @ 7 Nov 2011 01:13 PM
@cricketer maybe you are running in an infinite loop fr some test case :)

To all-- can u please tell

jravi96 @ 10 Nov 2011 02:49 PM
To all-- can u please tell whether the output for the queries is to be printed at collectively for all queries or one by one for each query?

@jravi96 - it doesn't matter

shettynamit @ 10 Nov 2011 10:57 PM
@jravi96 - it doesn't matter if you do it one by one or collectively - all up to u as long as it is correct and runs under the specified time :)

Can the same two people meet

ambujpandey @ 11 Nov 2011 12:54 PM
Can the same two people meet again within 1 second? Would that count?

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com