Bessie's Interview
Time limit2sMemory limit1024 MB
Given K farmers and N cows with interview durations, find when cow N+1 starts her interview and which farmers could interview her.
- Level
Medium7 of 10
- Topics
- Heap, Union-find, Simulation
- Solved
- No attempts yet
Problem
Bessie is looking for a new job! Luckily, farmers are hiring right now and holding interviews. Jobs are very competitive, so the farmers have decided to number the cows in the order they applied and interview them in that order. There are cows that applied before Bessie, so her number is ().
The interview process works as follows. At time , farmer starts interviewing cow for each . When a farmer finishes an interview, he immediately starts interviewing the next cow in line. If several farmers finish at the same time, the next cow may be interviewed by any of the available farmers, of her choice.
For each , cow 's interview takes exactly minutes (). Bessie knows these values, but she does not know which farmer each cow prefers.
Bessie wants to prepare carefully. She needs to know when her interview begins and which farmers could interview her. Find this information.
Input
The first line contains two integers and .
The second line contains integers .
Output
On the first line, print the time at which Bessie's interview begins.
On the second line, print a bit string of length . The -th bit is if farmer could interview Bessie, and otherwise.