#SRD0000042. Vua Kẹo
Bài tập thuộc lộ trình
Mục lục đề ⌄
Vua Kẹo
Vua Kẹo
Source: VNOJ
Version: Phuoc Hung OJ Extended
Problem Statement
There are people arranged in positions through . Person has candies. Position is a candy king if its count equals the sum of all counts to its left:
The sum before position is . Each of updates p x assigns and then asks for any valid candy-king position. Output -1 if no such position exists. Multiple correct indices may exist.
Input
The first line contains , the next line contains the initial candy counts, and the next lines each contain p x.
Output
After each assignment, output any valid king index or -1 if no king exists.
Subtasks
- Subtask 1 (15 points): ; ; ; a query may have multiple valid answers.
- Subtask 2 (25 points): ; ; ; a query may have multiple valid answers.
- Subtask 3 (25 points): ; ; ; a query may have multiple valid answers.
- Subtask 4 (35 points): ; ; ; a query may have multiple valid answers.
Examples
Input
3 4
2 2 3
1 1
1 2
2 4
3 6
Output
3
2
-1
3
Explanation
Initially . Set to get , in which index is valid. Restore , and index becomes valid. Setting removes all kings; finally setting makes index valid.