PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000180. Tìm vị trí theo tổng tích lũy (K-th by Cumulative Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tìm vị trí theo tổng tích lũy (K-th by Cumulative Sum)
K-th by Cumulative Sum
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative integers , for each positive integer query , find the smallest index () satisfying . Print -1 if no such index exists. Queries do not change the array.
Input
The first line contains . The second contains integers . The third contains thresholds .
Output
Print q lines, each containing the smallest corresponding index or -1.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Example 1
Input
5 5
0 2 0 3 0
1 2 3 5 6
Output
2
2
4
4
-1
Explanation
The prefix totals are 0,2,2,5,5. Ticket 2 first reaches its threshold at index 2; 6 exceeds the total.
Example 2
Input
3 2
0 0 0
1 10
Output
-1
-1
Explanation
All prefix totals are zero, below every positive threshold.