For this Question: There are N people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (N - 1)<sup>th</sup> person is at the back of the line. You are given a 0- indexed integer array tickets of length N where the number of tickets that the i<sup>th</sup> person would like to buy is tickets[i]. Each person takes exactly 1 second to buy a ticket. A person can only buy 1 ticket at a time and has to go back to the end of the line (which happens instantaneously) in order to buy more tickets. If a person does not have any tickets left to buy, the person will leave the line. Find the time taken for the person at position K (0- indexed) to finish buying tickets.First line contains two integers N and K.
Next line contains N space separated integers.

Constraints
1 <= N <= 1000
0 <= K < N
1 <= tickets[i] <= 100
Print the time taken for the person at position K (0- indexed) to finish buying tickets.Sample Input 1:
3 2
2 3 2

Output 
6

Explanation:
In the first pass, everyone in the line buys a ticket and the line becomes [1, 2, 1].
In the second pass, everyone in the line buys a ticket and the line becomes [0, 1, 0].
The person at position 2 has successfully bought 2 tickets and it took 3 + 3 = 6 seconds.

Sample Input 2:
4 0
5 1 1 1

Output
8

Explanation
In the first pass, everyone in the line buys a ticket and the line becomes [4, 0, 0, 0].
In the next 4 passes, only the person in position 0 is buying tickets.
The person at position 0 has successfully bought 5 tickets and it took 4 + 1 + 1 + 1 + 1 = 8 seconds., I have written this Solution Code: import java.io.*;
import java.util.*;

class Main{
    static class Solution {
        class pair{//To store the index and the value 
            int index;
            int value;
            pair(int index, int value )//Parameterised Constructor
            {
                this.index= index;
                this.value= value;
            }
        }
        public int timeRequiredToBuy(int[] tickets, int k) {
            Queue<pair> q= new ArrayDeque<>();
            for ( int i= 0; i< tickets.length; i++){//Adding all the element 
                q.offer( new pair( i, tickets[i] ) );
            }
            int  time= 0;
            while (!q.isEmpty())
            {
                pair temp= q.poll();//removing element from the front of the Queue
                time+= 1;//Increasing the timer 
                if ( temp.value > 1 ){
                    q.offer( new pair( temp.index, temp.value-1 ) );//adding the element into the queue
                    continue;
                }
                if ( temp.value == 1 ){//all tickets collected scineraio 
                    if ( temp.index == k )//desired index
                        return time;
                    continue;
                }
            }
            return time;
        }
    }
	public static void main (String[] args)throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	    int n,k;
    	    String line = br.readLine();
    	    String[] strs = line.trim().split("\\s+");
    	    n=Integer.parseInt(strs[0]);
    	    k=Integer.parseInt(strs[1]);
    	    line = br.readLine();
    	    strs = line.trim().split("\\s+");
    	    int[] tickets=new int[n];
    	    for(int i=0;i<n;i++){
    	        tickets[i]=Integer.parseInt(strs[i]);
    	    }
    	    Solution obj=new Solution();
    	    System.out.print(obj.timeRequiredToBuy(tickets,k));
	}	
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not?