PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000285. Học sinh thay phấn (Find the Student that Will Replace the Chalk)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Học sinh thay phấn (Find the Student that Will Replace the Chalk)
Find the Student that Will Replace the Chalk
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A class has students numbered through . They take turns in cyclic order starting at 0. Initially there are pieces of chalk. Student consumes pieces on each turn if enough remain; otherwise that student replaces the chalk. Find the first student who must replace it.
Input
First line: . Second line: exactly integers .
Output
Print the zero-based index of the student replacing the chalk.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; all are equal.
- Subtask 3 (50 points): ; ; .
Example 1
Input
3 22
5 1 5
Output
0
Explanation
Each round uses 11 pieces. Two rounds exhaust the supply; student 0 replaces it.
Example 2
Input
4 25
3 4 1 2
Output
1
Explanation
Two rounds consume 20. Student 0 uses 3 of the remaining 5; student 1 needs 4 but only 2 remain.