Problems > Position of the K-th One

Position of the K-th One

Difficulty: 1200 3500 ms 128 MB

implementation binary-search

Given a binary string, answer Q queries: where (1-based) is the K-th 1? Print −1 if there are fewer than K ones.

Input: the first line has the binary string; the second line has Q; the next Q lines each have one K.

Output: Q lines with the positions.

Constraints:

  • 1 ≤ length, Q ≤ 105

Sample Tests

Input 1
10101
2
2
4
Output 1
3
-1
Input 2
0
1
1
Output 2
-1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.