Computer Science, asked by thalarikavitha314, 9 months ago

A Company has decided to give some gifts to all of its employees. For that, company has given some rank to each employee. Based on that rank, company has made certain rules to distribute the gifts. The rules for distributing the gifts are: Each employee must receive at least one gift. Employees having higher ranking get a greater number of gifts than their neighbours. What is the minimum number of gifts required by company? 1 < T < 10 1 < N < 100000 1 < Rank < 10^9

Answers

Answered by kmsnsxpvpahtslmbkp
3

Answer:

import java.util.Scanner;

class minimumGifts

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in); //creating object for sccaner

byte T=sc.nextByte();

byte i=0,total,p,N,a,cu,pre;

while(i<T)

{

 total=1;

 p=1;

 N=sc.nextByte();

 pre=sc.nextByte();

 for(a=1;a<N;a++)

 {

  cu=sc.nextByte();

  if(cu>pre)

   p++;

  else

   p=1;

  total+=p;

  pre=cu;

 }

 System.out.println(total);

 i++;

}

}

}

Explanation:

2 Loops

1 for test cases

2nd for taking ranks and calculating gifts

Similar questions