#CCBCHBAHAI0000051. Sửa vòng lặp duyệt sai cận (Fix an Off-by-One Array Loop)
Sửa vòng lặp duyệt sai cận (Fix an Off-by-One Array Loop)
Fix an Off-by-One Array Loop
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
An array has logical size , so its valid indices are . A program intends to traverse it using for (i = 0; i <= b; ++i) and accesses at every iteration.
Determine whether this loop is safe. If , the first out-of-bounds access occurs at index . Do not attempt to predict the value of because that access is outside the valid array range.
Input
One line contains two integers and , where and .
Output
- If every index from through is valid, print
SAFE. - Otherwise print
OUT_OF_BOUNDS x, where is the first invalid index.
Subtasks
Subtask 1 (20 points): , .
Subtask 2 (30 points): , .
Subtask 3 (50 points): , .
Examples
Input
5 5
Output
OUT_OF_BOUNDS 5
Explanation
For , only indices are valid. Since the loop condition is , after processing it still executes once with . Index is outside the array, so the first invalid index is .