Sonya and string shifts
Practice
3.9 (19 votes)
Arrays
Data structures
Medium
Problem
28% Success 694 Attempts 50 Points 10s Time Limit 256MB Memory 1024 KB Max Code
Pussycat Sonya has a string S of length N. And she's asked Q queries of form: What is the minimal number of circular shifts in left direction of string S she needs to perform to get lexicographically smallest string, if she can do Ki such shifts at most?
Input:
The first line of input contains one integer N - the length of the string S.
The second line contains string S.
The third line contains one integer Q - the number of queries.
Each of the next Q lines contains one integer Ki.
Output:
Print the answers for all queries.
Constraints:
1 ≤ N, Q ≤ 106
0 ≤ Ki < N
Submissions
Please login to view your submissions
Similar Problems
Points:50
15 votes
Tags:
ArraysData StructuresMedium
Points:50
2 votes
Tags:
ApprovedArraysData StructuresMediumSegment Trees
Points:50
3 votes
Tags:
Advanced Data StructuresArraysData StructuresString Manipulation
Editorial