Tricks of the Trade
시간 제한7초메모리 제한1024 MB
연속한 로봇 구간을 사서 그중 정확히 K개를 팔아 이익을 최대로 만들고, 최적 거래에 포함될 수 있는 로봇을 모두 표시한다.
문제
Since your career as an art thief turned out to be decidedly less glamorous than you had hoped for, you have set your eyes on a new target: you want to steal a medal at this year’s CEOI!* So far your evil plan is working as intended: The Scientific Committee, still confused about the oil shortage you had arranged, immediately fell for your feigned hacking attempt. And when they let you into their secret headquarters to help plan the rejudging, you could easily steal the combination for the safe in which the medals are stored…
However, the next phase of your plan will require an assistant, and right now you don’t have enough money to hire one. Fortunately, you just found an opportunity to fix this problem. A shop you stumbled upon in Berlin sells programmable vacuum cleaner robots, numbered from to . Robot costs euros. Unfortunately, the vendor will only sell you a full, contiguous segment of robots: If you want to buy robots and , then you must buy every robot with .
As your fellow contestants are quite fond of robots, you promised to sell them of these robots (). They will pay you euros for robot , and you hope to make a good profit in the process.
Write a program that
- computes the maximum profit you can make by buying a segment of at least robots and selling exactly robots of this segment to the other contestants, and
- determines which robots you might sell to the other contestants as part of such a transaction with maximum profit.†
* Obviously, the problem was with the art, not the thefts.
† After all, you might find some use for robots that you keep…
입력
The first line of input contains the numbers and as described above. The second line contains the integers . Finally, the third line contains the integers .
출력
Your program should output two lines. The first line should contain a single integer, the maximum profit you can achieve. On the second line, you should output a binary string of length : the -th character should be if you might sell the -th robot in some transaction with maximum profit and otherwise.
힌트
In the first example, you can buy the third to fifth robot and sell all three of them to your fellow contestants. This costs you euros, while the contestants will only pay you euros for these robots, so you lose 1 euro. If you buy any other segment of robots, you would lose even more money.
In the second example, you can buy the first to third robot and sell the first and third robot to your fellow contestants. This costs you euros, while the contestants will pay you euros, so your profit is euros. No other segment of robots would give you a higher profit. However, you could also buy the third and fourth robot, and sell both of them, or buy the third to fifth robot, and sell the third and fifth robot. In both cases, your profit would also be euros, and so all robots except for the second robot can be part of a transaction with maximum profit.