write the solution of the program by python 3 language :
I need the program using list :
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input
The first line of input will contain an integer n (1 ≤ n ≤ 105),
the number of events. The next line will contain n space-separated
integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output
Print a single integer, the number of crimes which will go
untreated.
Examples
input
3
-1 -1 1
output
2
input
8
1 -1 1 -1 -1 1 1 1
output
1
input
11
-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1
output
8
Note
Lets consider the second example:
1- Firstly one person is hired.
2- Then crime appears, the last hired person will investigate this
crime.
3- One more person is hired.
4- One more crime appears, the last hired person will investigate
this crime.
5- Crime appears. There is no free policeman at the time, so this
crime will go untreated.
6- One more person is hired.
7- One more person is hired.
8- One more person is hired.
The answer is one, as one crime (on step 5) will go untreated.
Python code:
#number of cases
n=int(input())
#list of integer values
integers=list(map(int,input().split()))
#number of free police
police=0
#number of crimes
crime=0
#looping through integers
for i in integers:
#checking if police is free
if(i==-1 and police>0):
#decrementing value of free police
police+=i
#checking if police is not free
elif(i==-1 and police==0):
#incrementing value of crime
crime-=i
#assiging a police
else:
#adding the number of police
police+=i
#printing number of crimes
print(crime)
Screenshot:
Input and Output:
write the solution of the program by python 3 language : I need the program using...
write the solution of the program by python 3 language : I need the program using list : Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard....
write the solution of the program by python 3 language : I need the program using list : You are given a non-decreasing sequence of n positive integers a1,a2,…,an. Print the number of distinct values in the sequence. For example, if the sequence is 1,2,2,2,3,4,4,5,7,10, the answer is 6 since distinct values are 1,2,3,4,5,7,10. Input The first line contains a positive integer n (1≤n≤1000) — the length of the sequence. The second line contains n space-separated positive integers a1,a2,…,an (1≤ai≤1000)...
write the solution of the program by python 3 language : I need the program using list : You are given a sequence of n positive integers a1,a2,…,an, where n is even. Swap adjacent elements in the given sequence and print the resulting sequence: a2,a1,a4,a3,a6,a5,… Input The first line contains a positive even integer n (2≤n≤1000) — the length of the sequence. The second line contains n space-separated integers a1,a2,…,an (1≤ai≤1000) — the elements of the sequence. Output Print n...
write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other in the sequence. Input The first line contains an integer n...
write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : i have 15 min to submit the solution please help me You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other...
write the solution of the program by python 3 language : I need the program using list : A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time...
write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : Alex got a sequence of n integers a1,a2,…,an as a birthday present. Alex doesn't like negative numbers, so he decided to erase the minus signs from all negative numbers. As a result, he got a sequence of non-negative numbers. Print the resulting sequence. For example, if the sequence is 1, 5, -3, 4,...
All statistical tests are carried out at a =0.05. QUESTION ONE The following output represents data collected for the study of manpower allocation in the Ghana Police Service from various district across the country. The study involved testing the association among the key variables; comprising - Crimes (The number of reported crimes); Officers (The number of full-time equivalent police officers); Support (The number of civilian support staff); Unemployed (The unemployment rate); Retired (The percentage of the local population who are...
plo:0 3G STAY HOME I.. 3 من 3 2 is 1 Does CompStat Reduce Crime? CASE STUDY SELBdsde COM STAT ) the comparison with the pre s tand New York City Police purtment NYPD) for establishing trends The Compania in 1991 when Brason was police Issues weekly commander profile porto ser compartir measure the performance of precinct commander city-wide s that reconds all spend time or The weekly commander profile reports include cumplaints and summer and in each Information on...
//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...