You are not logged in. Please login at www.codechef.com to post your questions!

×

# Please Tell Why this code is giving Wrong Answer on Submission on CodeChef.

 -1 Problem Statement: Recently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (which is in the point (0, 0)) and carry it to some table (which is in some point (x, y)) in a shortest way. But this is a beta version of robots and they can only do the next moves: turn right and make a step forward or turn left and make a step forward. Initially they look in direction of X-axis. Your task is to calculate for each query the number of moves they’ll do to reach corresponding table. Input The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. For each test case there is a sing line containing two space-separated integers - x and y. Output For each test case, output a single line containing number of moves that robot will make to reach point (x, y) Constraints 1 ≤ T ≤ 105 -109 ≤ x, y ≤ 109 Example Input: 2 3 3 3 4 Output: 6 7 My Code {In JAVA} import java.util.Scanner; class Main { public static void main(String args[]) { int t; int coordinates[]; int i = 0,j = 0,k; int pos=0; int result[]; int xpos,ypos; try { Scanner sc = new Scanner(System.in); t=sc.nextInt(); coordinates = new int[2*t]; result = new int[t]; while(i=0 && coordinates[ypos]>=0) { result[i]= coordinates[xpos] + coordinates[ypos]; } else if(coordinates[xpos]<=0 && coordinates[ypos]>=0) { coordinates[xpos] = -1*coordinates[xpos]; result[i]= coordinates[xpos] + coordinates[ypos]; } else if(coordinates[xpos]<=0 && coordinates[ypos]<=0) { coordinates[xpos] = -1*coordinates[xpos]; coordinates[ypos] = -1*coordinates[ypos]; result[i]= coordinates[xpos] + coordinates[ypos]; } else if(coordinates[xpos]>=0 && coordinates[ypos]<=0) { coordinates[ypos] = -1*coordinates[ypos]; result[i]= coordinates[xpos] + coordinates[ypos]; } i++; } for(i=0;i

 1 Please delete the post.Its an ongoing contest.Please do not discuss strategy, suggestions or tips in the forum during a live contest. answered 13 Jul '14, 12:09 3★yoyo123 51●2●9 accept rate: 14%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,508
×1,180
×777
×242
×43

question asked: 13 Jul '14, 10:53

question was seen: 1,647 times

last updated: 13 Jul '14, 12:09