Official

B - Personnel Change Editorial by en_translator


As instructed in the problem statement, we may find the number of employees in each department in the current and next seasons, and print the difference.

Sample code (Python)

N, M = map(int, input().split())
X = [0] * M # The number of employees in the current season
Y = [0] * M # The number of employees in the next season
for _ in range(N):
    A, B = map(int, input().split())
    X[A - 1] += 1
    Y[B - 1] += 1
for j in range(M):
    print(Y[j] - X[j])

In fact, the arrays \(X\) and \(Y\) in the sample code above can be combined:

Sample code (Python)

N, M = map(int, input().split())
ans = [0] * M
for _ in range(N):
    A, B = map(int, input().split())
    ans[A - 1] -= 1
    ans[B - 1] += 1
for v in ans:
    print(v)

posted:
last update: