USACO 2020 December Contest Bronze Problem 2

Hi Everyone,

I was working on the USACO 2020 December Contest Bronze Problem 2, and I did not understand the problem statement.

Here is my code:

public class UsacoPractice7
{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String numOfFlowers = br.readLine();
        String amountOfPetals = br.readLine();

        String[] petals = amountOfPetals.split(" ");

        int size = petals.length;
        int [] arr = new int [size];
        for(int i = 0; i < size; i++)
        {
            arr[i] = Integer.parseInt(petals[i]);
        }

        List<Integer> listOfPetals = new ArrayList<>(arr.length);

        for (int i : arr)
        {
            listOfPetals.add(Integer.valueOf(i));
        }
        //System.out.println(listOfPetals);

        int count = listOfPetals.size();


        for(int i = 0; i < listOfPetals.size(); i++)
        {
            int sum = listOfPetals.get(i);
            for(int j = i + 1; j < listOfPetals.size(); j++)
            {
                sum = sum + listOfPetals.get(j);
                if (sum % (j - i + 1) == 0)
                {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}

What don’t you understand about the problem statement?

This is what I understood so far in the problem:

There are N flowers and the cow took a picture of them in range (i, j). I have to see in that range if the average number of petals is an integer. If it is then it is an average flower. Did I miss anything? I submitted the above code and it failed for cases 2 - 10, but worked for case 1.

You’re half right. You can check if the average number of petals is an integer for some small constant factor optimization, but you mainly have to check if that “average” petal exists in that photo.