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.

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<t)
        {
            for(k=0;k<2;k++)
            {
            coordinates[pos] = sc.nextInt();
            pos++;
            }
            i++;
        }



        i=0;j=0;k=0;



        while(i<t)
        {
            xpos = i*2;
            ypos = xpos+1;

            if(coordinates[xpos]>=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<result.length;i++)
        {
            System.out.println(result[i]);
        }
    }

    catch(Exception e)
    {
        e.printStackTrace();
    }


}

}


Please tell what is the problem in the code. Because in my IDE its working fine and giving correct output. But when I submit it on codechef its giving "WRONG ANSWER" as result.

asked 13 Jul '14, 10:53

himanshul93's gravatar image

2★himanshul93
-411
accept rate: 0%


Please delete the post.Its an ongoing contest.Please do not discuss strategy, suggestions or tips in the forum during a live contest.

link

answered 13 Jul '14, 12:09

yoyo123's gravatar image

3★yoyo123
5129
accept rate: 14%

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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,284
×1,096
×704
×214
×38

question asked: 13 Jul '14, 10:53

question was seen: 1,621 times

last updated: 13 Jul '14, 12:09