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.
이번에도 영어로 막혔음...ㅠ
아래 문장 잘못 해석해서 이해를 못했다
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
모르는 단어 많았고 더듬더듬 단어 찾으면서 읽다가 untreated 검색했는데 치료되지 않은 이라 해서 엥 치료를 해야하나? 했음. 그래서 치료랑 관련있나 싶어서 다시 읽었다. (ㅠ 독해 제발) 지금 파파고로 단어 검색하니 여기서는 처리되지 않은 으로 뜨네. 이게 맞는 말 같다.
발생한 범죄와 고용한 숫자의 시간 순서가 주어졌고 처리되지 않은 범죄를 찾아라? 라는 문장인듯
푸는 건 적당히 입출력 보고 이해했다. n개의 정수가 주어지는데 -1은 범죄가 발생한거고 양의 정수는 고용한 숫자. 그리고 사람은 범죄를 한 건 밖에 처리하지 못한다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
using namespace std;
using i64 = long long;
int main() {
int n;
scanf("%d", &n);
int now = 0;
int count = 0;
for(int i = 0; i< n; i++){
int input;
scanf("%d", &input);
if(input == -1){
now--;
if(now < 0)
count++;
}
else {
if(now < 0)
now = 0;
now += input;
}
}
printf("%d", count);
return 0;
}
푸는 건 쉬웠다. 쉬웠는데 빨리 짜느라 정신 없어서 생각나는대로 바로바로 코딩했음. now는 현재 고용된 경찰 인원을 세서 범죄를 처리하는 변수이고 count는 처리하지 못한 범죄의 수이다.
'코드포스' 카테고리의 다른 글
[코드포스 Practice6] C. Food on the Plane (0) | 2019.12.04 |
---|---|
[코드포스 Practice6] B. Mammoth's Genome Decoding (0) | 2019.12.04 |
[코드포스 Practice6] 후기 (0) | 2019.12.03 |
[코드포스 Practice5] E. Joty and Chocolate (0) | 2019.11.29 |
[코드포스 Practice5] D. K-Dominant Character (0) | 2019.11.27 |