English, asked by tejaswitej00, 9 months ago

How to attempt?
Question :
Apple Orchard
Allie has bought a new apple orchard. The orchard has a single file of trees, number
from 1 to N. Each tree has a certain number of ripe apples.
Allie has a rule she wants to follow. She wants to pluck an equal amount of apples fro
each tree from which she collects apples.
Allie can start collecting apples from any tree, but once she starts collecting, she coll
from every consecutive tree until she reaches the last tree she wants to collect from.
the maximum number of apples she can fetch from the orchard.
Input Specification:
Input1: N, the number of trees.
Input2: An array of N elements (a1,a2 a3......AN], denoting the number of ripe
apples in each tree of the orchard.
Output Specification:​

Answers

Answered by monishkumarreddy17
38

Answer: Java Solution:

public class str {

   public static void main(String[] args) {

int a[]={80,48,82};  // {8,40,77}

Arrays.sort(a);

       System.out.println(Arrays.toString(a));              

ArrayList<Integer>a1=new ArrayList<>();                        

for(int i=a.length-1;i>=0;i--){      

   int x=0;

   x=a[i]*(a.length-i);

   a1.add(x);

}

       System.out.println(a1);

      for(int i=0;i<a1.size();i++){

          if(a1.get(a1.size()-1-i)>=a1.get(i)){

              System.out.println(a1.get(a1.size()-1-i));

              break;

          }

      }

}

}

Explanation:

Similar questions