[Huawei OD Unified Exam B Paper | 100 points] Desert Island Survival (C++ Java JavaScript Python)

Huawei OD Online OJ:

Users who have already purchased this column, please private message the blogger to open an account and brush up questions online! ! !

Online OJ: brush the questions immediately

Question bank column: 2023 Huawei OD machine test (A volume + B volume) (C++JavaJSPy)

topic description

There are several people on a deserted island. There is only one road on the island leading to the ports at both ends of the island. Everyone needs to flee to the ports at both ends to escape.

Assume everyone moves at the same speed and can only choose to escape left or right.

If two people meet, they will have a duel, and the one with the strongest fighting power will survive and lose the same fighting power as the opponent; if the fighting power is the same, both will perish together.

enter description

Given a row of non-zero integer arrays, the number of elements does not exceed 30000;

Positive or negative means escape direction (positive means escape to the right, negative means escape to the left), absolute value means combat power, the number on the left means the closer to the port on the left, people with the same escape direction will never have a duel.

output description

The total number of people who can escape, output 0 if no one escapes, and output -1 when the input is abnormal.

Example

Guess you like

Origin blog.csdn.net/shangyanaf/article/details/132642671