Back
Close
  • 164

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

In this exercice you will implement a simple auto-scaling system: https://en.wikipedia.org/wiki/Autoscaling

You have different services S across the datacenter. Each instance of a service can handle a maximum number of clients.

You will receive a sequence of metrics M corresponding with the number of clients connected to each service, and you will need to scale your services in real time by providing the number of instances of services to start or to stop to handle the new load.

Positive value indicates that you want to start new instances of a service, negative value means that you want to stop instances of a service.

Instances number are rounded up; if you have 10 clients connected to a service that can handle 8 clients per instance, you will need 2 running instances of the service to handle the load: ceil(10/8) == ceil(1.25) == 2.

At the beginning no instances of services are running.
Input
Line 1: S and M, the number of services and the number of lines metrics
Line 2: S values, the number of clients that each service can handle
Line from 2 to 2+M: sequence of metrics representing number of clients connected to each service
Output
Line from 1 to M: The number of instances of service to start / stop for each line of metrics received
Constraints
0 < S ≤ 50
0 < M ≤ 100
Services can handle at least 1 client
Example
Input
4 3
5 10 4 3
20 5 10 7
25 3 14 16
15 4 20 10
Output
4 1 3 3
1 0 1 3
-2 0 1 -2

A higher resolution is required to access the IDE