█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 2778

Problema 0xf2 - Partir un arreglo grande en 2

  • Autor: hamorillo
  • Fecha: 2021-02-04 16:10:18 UTC (Hace casi 4 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#2
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#3
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#4
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#5
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#6
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#7
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#8
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#9
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#10
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#11
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#12
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#13
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#14
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#15
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#16
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#17
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#18
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#19
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
#20
Error de compilación
                      Main.java:3: error: class ex0xf2 is public, should be declared in a file named ex0xf2.java
public class ex0xf2 {
       ^
1 error

                    
Puntos totales: 0 / 100

Código

import java.util.Scanner;

public class ex0xf2 {
    public static void main(String[] args) {
        Data data = readNumsFromStdin();

        long totalSum = calculateTotalSum(data.numbers);
        long leftSum = 0;
        long rightSum = totalSum;

        for (int i = 0; i < data.totalNumbers - 1; i++) {
            leftSum += data.numbers[i];
            rightSum -= data.numbers[i];

            if (leftSum > 0 && rightSum < 0) {
                System.out.println(i + 1);
                return;
            }
        }

        System.out.println("Impossible");
    }

    private static long calculateTotalSum(int[] numbers) {
        long sum = 0;

        for (int num : numbers) {
            sum += num;
        }
        return sum;
    }

    private static Data readNumsFromStdin() {
        Data data = new Data();
        Scanner in = new Scanner(System.in);

        data.totalNumbers = in.nextInt();
        data.numbers = new int[data.totalNumbers];
        readArrayFromStdin(data.numbers, data.totalNumbers, in);

        return data;
    }

    private static void readArrayFromStdin(int[] array, int count, Scanner in) {
        for (int i = 0; i < count; i++) {
            array[i] = in.nextInt();
        }
    }

    private static class Data {
        int totalNumbers;
        int[] numbers;
    }
}