No.607 777th Anniversary of Opening
Problem Statement
Railway company A celebrates its 777th anniversary this year. To commemorate this, it has decided to hold a "777 Campaign".
The campaign is as follows: "Run a train of N cars over M stations' worth of travel, and it is a success if, in some section, there are multiple consecutive cars whose numbers of passengers sum to 777 (or a single car with 777 passengers)."
For each section, you are given data on the increase or decrease in the number of passengers compared to the previous section. Output whether the campaign succeeded.
Initially, the number of passengers in every car is 0, and there is no upper limit on the number of passengers.
It is also guaranteed that the number of passengers is at least 0 in every section.
Input
N M a1_1 a1_2 ------ a1_N a2_1 a2_2 ------ a2_N -------- aM_1 aM_2 ------ aM_N
Integers N and M are given, indicating that a train of N cars ran for M stations' worth of travel. Each of the following M lines gives, for the N cars, the increase or decrease in the number of passengers compared to the previous section. A positive number indicates an increase, and a negative number indicates a decrease.
1<=N,M<=1000
-1000<=ai_j<=1000
Output
Output "YES" or "NO" according to whether the condition was satisfied and the campaign succeeded.
Print a newline at the end.
Sample
Sample 1
Input
5 3 10 700 0 0 3 0 0 70 7 -1 1 1 1 1 1
Output
YES
In this case, a train of 5 cars ran for 3 stations' worth of travel. The numbers of passengers are as follows:
In the 1st section: 10 700 0 0 3
In the 2nd section: 10 700 70 7 2
In the 3rd section: 11 701 71 8 3
In the 2nd section, the numbers of passengers in the consecutive cars 2, 3, and 4 sum to 777, so the campaign is a success.
Sample 2
Input
6 1 350 350 70 2 3 4
Output
NO
This time the train ran for only one station's worth of travel. The numbers of passengers in cars 1, 2, 3, 5, and 6 sum to 777, but these cars are not consecutive, so the campaign is a failure.
Sample 3
Input
5 5 100 0 100 0 100 200 100 200 100 200 300 200 300 200 300 100 -100 -200 -100 200 0 -200 -330 -200 -793
Output
YES
A train of 5 cars runs for 5 stations' worth of travel. The final numbers of passengers are 700 0 70 0 7. Although this includes cars with 0 passengers in between, the numbers of passengers in the consecutive cars 1, 2, 3, 4, and 5 sum to 777, so the campaign is a success.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
gotutiyan
tsutaj