#P9732. [CEOI 2023] Trade
[CEOI 2023] Trade
Background
Translated from CEOI 2023 Day 2 T1 Trade.
Problem Description
There are robots in a line. The purchase price of the -th robot is euros, and the selling price is euros.
Given , you need to buy all robots in some interval of length at least , and then choose exactly robots among them to sell.
You need to find:
- The maximum profit you can obtain.
- Under the condition that the profit is maximized, which robots can be sold in some optimal plan.
Input Format
The first line contains two integers .
The second line contains positive integers .
The third line contains positive integers .
Output Format
The first line outputs one integer, the maximum profit.
The second line outputs a 01 string. The -th character should be 1 if the -th robot can be sold in some optimal plan; otherwise output 0.
5 3
3 5 2 3 6
2 1 5 2 3
-1
00111
5 2
1 6 1 5 2
4 1 6 2 4
2
10111
Hint
In sample 1, the optimal plan is to buy robots and then sell them, but you still lose euro.
In sample 2, the maximum profit is euros. You can buy and sell . You can also buy and sell . You can also buy and sell . Therefore, robots may be sold in some optimal plan, so output 10111.
Constraints
For all testdata, , .
- Subtask 1 (5+5 points): .
- Subtask 2 (5+5 points): .
- Subtask 3 (5+5 points): .
- Subtask 4 (10+15 points): .
- Subtask 5 (25+20 points): No special constraints.
In each subtask, if the first line of the output is correct, you can get the first half of the subtask score. If the second line is also correct, you can get the full score of the subtask.
Translated by ChatGPT 5