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 2111. Plato

Что не так пишет неверный ответ все пересчитал ответы правильные дает
Posted by Евгений 8 Oct 2021 15:49
import java.util.Scanner;
public class Main
{
    public static void main(String[] args) {
        Scanner a = new Scanner(System.in);
        int x = a.nextInt();
        //String x1 = a.nextLine();
        int y = 0;
        int z = 0;
        int [] array1 = new int[x];
        for(int i=0;i<x;i++)
        {
            array1[i] = a.nextInt();
            y+=array1[i];

            if(i==1 && array1[i] < array1[i-1] )
                {
                    int tmp = array1[i];
                    array1[i] = array1[i-1];
                    array1[i-1] = tmp;
                }
        }

        for(int i=array1.length-1;i>-1;i--)
        {
            z+=array1[i]*y;
            y-=array1[i];
            z+=array1[i]*y;
        }

        System.out.println(z);
    }
}