luogu#P6958. [NEERC2017] The Great Wall
[NEERC2017] The Great Wall
题目描述
Recently you had become an emperor of a small country of Sinai. You had decided to build a big wall at the border to save your country from barbarian raids. You had contacted W Corp
, the only company in the world that builds non-penetrable walls.
W Corp
builds each wall using the same pattern. The length of the wall is meters. Each one-meter piece of the wall is numbered by an integer from to along its length and may have a different height. The height pattern is based on three fixed arrays a , , and of elements each, such that for all , and an integer . These arrays and are the same for any wall that is built by W Corp
.
The choice of the specific wall design is determined by two distinct integers and in the following way. Take two ranges of integers: [x , and [y , (these ranges are inclusive of their ends). Then the height of the wall at one meter piece for all is equal to:
if does not belong to any of the chosen ranges;
if belongs to exactly one chosen range;
if belongs to both chosen ranges.
A strength of a wall is defined as the sum of all heights of its one meter pieces.
The arrays a , , and an integer are the same for any wall built by W Corp
, so the company provides a price list with all the possible wall designs, sorted in non-decreasing order of their strength. You choose the k-th wall design from the list. The task is to find the strength of the chosen wall.
输入格式
The first line of the input contains three integers and $k (2 \le n \le 30 000 , 1 \le r < n , 1 \le k \le (n−r)(n−r+1)/2)$ -- the length of the wall, the length of the segments to choose, and the position of the wall in the price list.
The second line of the input contains the elements of the array a
The third line of the input contains the elements of the array
The fourth line of the input contains the elements of the array
输出格式
Print one integer -- the strength of the k-th wall from W Corp
price list.
题目大意
最近你成为了西奈一个小国家的皇帝。你决定在边界建造一座长城保护你的国家不被野蛮人抢劫。你联系了“W Corp”——世界上唯一的建造坚不可摧的墙的公司。
“W Corp”用相同的格式建造所有墙。墙的长度是 米,每一米墙按顺序从 到 编号,它们可能有不同的高度。高度的格式取决于三个固定的数组 ,它们各有 个元素,对于任意 满足 ,还有一个整数 。三个数组和 对于“W Corp”建造的任何墙都是相同的。
按照如下方式,具体的墙体设计的选择取决于两个不同的整数 。取两个整数区间: 和 (区间包括端点)。那么第 米墙的高度是:
- ,当 不属于这两个区间
- ,当 属于这两个区间中的恰好一个
- ,当 属于这两个区间中的两个
墙的强度定义为每一米墙高度的和。
在“W Corp”建造的所有墙中,数组 和整数 都是固定的。公司提供了一份所有可能的墙体设计的列表,按照强度单调不减排序。你选择了其中第 种墙体设计。你的任务是,求出你选择的墙的强度。
输入格式
第一行包括三个整数 $n,r,k\ (2\le n\le 30000,\ 1\le r < n,\ 1\le k\le \frac{(n-r)(n-r+1)}{2}\ \ )$,分别代表墙的长度,取的区间的长度,你的选择在列表中的位置。
第二行包括了数组 的元素,。
第三行包括了数组 的元素,。
第四行包括了数组 的元素,。
输出格式
输出一个整数,“W Corp”的列表中第 种墙的强度
样例解释
在样例中,能建造出的不同的墙有三种:
- 选择 ,墙的高度是 ,强度是 。
- 选择 ,墙的高度是 ,强度是 。
- 选择 ,墙的高度是 ,强度是 。
4 2 1
1 2 3 4
3 3 5 5
7 7 7 7
16
提示
Time limit: 3 s, Memory limit: 512 MB.