ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1910. Titan Ruins: Hidden Entrance

Test #2 RE Java Code. What's wrong?
Posted by Apurv Nagar 28 Nov 2015 19:25
CODE:-

import java.util.*;
public class titans
{
    public static void main (String[] args) throws java.lang.Exception
    {
        int ind = 0; int w = 0;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = sc.nextInt();
        }
        int largest = a[0] + a[1] + a[2];
        if (n%2 != 0 )
        {
            w = (n/2) + 1;
        }
        else
        {
            w = n/2;
        }
        for (int j = 0; j <= w; j++)
        {
            int new_long = a[j] + a[j+1] + a[j+2];
            if (new_long >= largest)
            {
                largest = new_long;
                ind = j + 2;
            }
        }
        System.out.println(largest + " " + ind);
    }
}
----------------------------------------------------------
Please tell where am I going wrong. The code is working fine on my system. Thanks in advance.
-----------------------------------------------------------
Thanks for your time but I have found the solution - thanks again!

Edited by author 28.11.2015 19:30