#C12691. Task Distribution Across Time Slots

    ID: 42146 Type: Default 1000ms 256MiB

Task Distribution Across Time Slots

Task Distribution Across Time Slots

You are given a set of tasks and a sequence of time slots. Each task has a name and a required duration (in hours). Each time slot is associated with a day and the available hours on that day. Your goal is to distribute the tasks sequentially across the given time slots. A task may be split over multiple time slots if its duration exceeds the remaining available time in a slot. For each time slot (day), assign as many hours as possible from the current task until the available time is used up, then move on to the next time slot. Note that if a task is not completely assigned in one slot, the remaining part will be assigned in subsequent slots.

In mathematical terms, for each day with available time (t), and assignments (a_{i}) (the number of hours from a task), the following holds: [ \sum_{j} a_{ij} \le t]

Make sure that the final distribution satisfies the sequential order of tasks and that the sum of assigned hours for each day does not exceed its available time.

inputFormat

The input is read from standard input (stdin) and has the following format:\n\nThe first line contains an integer (N), the number of tasks.\nEach of the next (N) lines contains a task name (a string without spaces) and an integer representing its duration (in hours), separated by a space.\nThe next line contains an integer (M), the number of time slots.\nEach of the following (M) lines contains a day (a string without spaces) and an integer representing the available hours on that day, separated by a space.

outputFormat

Output to standard output (stdout) a JSON object representing the distribution of tasks. The keys are the day names (in the order of input time slots) and the values are arrays of assignments. Each assignment is represented as an array of two elements: [task_name, assigned_hours]. The output must be a valid JSON string.## sample

3
Task_A 5
Task_B 3
Task_C 2
3
Monday 4
Tuesday 3
Wednesday 5
{"Monday": [["Task_A", 4]], "Tuesday": [["Task_A", 1], ["Task_B", 2]], "Wednesday": [["Task_B", 1], ["Task_C", 2]]}