eolymp
bolt
Try our new interface for solving problems
Problems

Gangsters

Gangsters

The goal is to gather the gangsters with the maximal total prosperity in the restaurant by opening and closing the door appropriately.\textit{ }\textbf{N} gangsters are going to a restaurant. The \textbf{i}-th gangster comes at the time \textbf{T_i} and has the \textit{prosperity }\textbf{P_i}. The door of the restaurant has \textit{\textbf{K}}+\textbf{1} \textit{states of openness} expressed by the integers in the range \[\textbf{0}, \textbf{K}\]. The state of openness can change by one in one unit of time; i.e. it either opens by one, closes by one or remains the same. At the initial moment of time the door is closed (state \textbf{0}). The \textbf{i}- th gangster enters the restaurant only if the door is opened specially for him, i.e. when the state of openness coincides with his \textit{stoutness }\textbf{S_i}. If at the moment of time when the gangster comes to the restaurant the state of openness is not equal to his stoutness, then the gangster goes away and never returns. The restaurant works in the interval of time \[\textbf{0}, \textit{\textbf{T}}\].1 The goal is to gather the gangsters with the maximal total prosperity in the restaurant by opening and closing the door appropriately. \InputFile The first line of the input contains the values \textit{\textbf{N}}, \textit{\textbf{K}}, \textit{\textbf{T}}, the second - \textit{\textbf{T}}\textbf{_1}, \textit{\textbf{T}}\textbf{_2}, ..., \textit{\textbf{T}}\textbf{_N}, the third - \textit{\textbf{P}}\textbf{_1}, \textit{\textbf{P}}\textbf{_2}, ..., \textit{\textbf{P}}\textbf{_N}. The forth - \textit{\textbf{S}}\textbf{_1}, \textit{\textbf{S}}\textbf{_2}, ..., \textit{\textbf{S}}\textbf{_N}. Numbers in rows are separated by spaces. \textbf{1} ≤ \textit{\textbf{N}} ≤ \textbf{100}; \textbf{1} ≤ \textit{\textbf{K}} ≤ \textbf{100}; \textit{\textbf{1}} ≤ \textit{\textbf{T}} ≤ \textbf{30 000}; \textbf{0} ≤ \textit{\textbf{T}}\textbf{_i} ≤ \textit{\textbf{T}}; \textbf{1} ≤ \textit{\textbf{P}}\textbf{_i} ≤ \textbf{300}; \textbf{1} ≤ \textit{\textbf{S}}\textbf{_i} ≤ \textit{\textbf{K}}; All values in the input are integers. \OutputFile Print to the output the single integer - the maximal sum of prosperity of gangsters in the restaurant. In case when no gangster can enter the restaurant the output should be \textbf{0}.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
4 10 20
10 16 8 16
10 11 15 1
10 7 1 8
Output example #1
26