#CCBCHBON0000012. Số âm đầu tiên (First Negative Value Position)
Số âm đầu tiên (First Negative Value Position)
First Negative Value Position
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Find the first 1-based index containing a negative value among integers, or print -1 if none exists. Use break to stop after the first match.
Input
First , followed by exactly integers in .
Output
The first negative position, or -1.
Subtasks
-
Subtask 1 (20%): ; .
-
Subtask 2 (30%): ; .
-
Subtask 3 (50%): ; .
Examples
Example 1
Input:
4
0 9 7 -1
Output:
4
Explanation:
Scan left to right; the first negative value determines the reported position.
Example 2
Input:
3
1 2 3
Output:
-1
Explanation:
Scan left to right; the first negative value determines the reported position.