pls give me complete code with explaination(use STL if possible)
https://practice.geeksforgeeks.org/contest-problem/last-k-element/0/
incase link is not available
Given N elements to be inserted into queue and a positive number K. The task is to reverse last K elements of queue.
Input:
First line of input contains number of testcases T. For each testcase, first line of input contains N, number of elements to be inserted in queue and K. Next line contains N elements.
Output:
For each testcase, print the modified queue if it is possible to reverse K elements, else print -1.
Constraints:
1 <= T <= 100
1 <= N <= 105
1 <= K <= 105
Example:
Input:
1
5 3
10 20 30 40 50
Output:
10 20 50 40 30
Explanation:
Testcase 1: After reversing last 3 elements, modified queue has elements as 10, 20, 50, 40, 30.