Question
On this input: 1 2 1 0 0 0 1 0 I am getting possible , but it should be impossible. Why? :) everything else
On this input: 1 2 1 0 0 0 1 0 I am getting "possible" , but it should be "impossible". Why? :) everything else is correct in the code
Code:
import sys
# Read the capacity and number of stations capacity, n = map(int, sys.stdin.readline().strip().split())
# Start with an empty train people_on_train = 0
# Loop through the stations for i in range(n): # Read the number of people that left, entered, and stayed at a station left, entered, stayed = map(int, sys.stdin.readline().strip().split())
# Update the number of people on the train people_on_train = people_on_train - left + entered
# Check if the number of people on the train exceeds the capacity if people_on_train > capacity: print("impossible") sys.exit(0)
# Check if there were passengers that had to wait in vain if stayed > 0 and people_on_train
# Check if the train finished the journey empty if people_on_train != 0: print("impossible") sys.exit(0)
# The measurements are consistent print("possible")
Output
One line containing one word: possible if the measurements are consistent, impossible otherwise.
Sample Input 1 | Sample Output 1 |
---|---|
1 2 0 1 1 1 0 0 | possible |
Sample Input 2 | Sample Output 2 |
---|---|
1 2 1 0 0 0 1 0 | impossible |
Sample Input 3 | Sample Output 3 |
---|---|
1 2 0 1 0 1 0 1 | impossible |
Sample Input 4 | Sample Output 4 |
---|---|
1 2 0 1 1 0 0 0 | impossible |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started