F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Range k-th Maximum Query

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 343    Accepted Submission(s): 111


Problem Description
你在学数据结构的时候碰到了如下问题:

给一个序列 $a_1, a_2, \dots, a_n$,求所有长度为$l$的子区间第$k$大的数的和。对于某个$i(1\leq i\leq n-l+1)$,将$a_i, a_{i+1}, \dots, a_{i+l-1}$所有的元素从大到小排序之后,得到$b_1, b_2, \dots, b_l$,其中的$b_k$就是所求的子区间$[i,i+l-1]$中第$k$大的数。对于其中所有的$i (1\leq i\leq n-l+1)$求和,就是想要的值。

比如一个序列为$3,1,5,2,4,1$,$l=4,k=2$,那么每个长度为$l$的区间中第$k$大的依次为$3,4,4$。

现在给你一个序列$c_1, c_2, \dots, c_n$,你想将其元素重新排列,使得这个和尽量大或者尽量小。问最大或者最小的和是多少。
 

Input
第一行一个正整数$T(1\leq T\leq 10^4)$表示数据组数。

对于每组数据,第一行三个整数$n, l, k(1\leq k\leq l\leq n\leq 10^5)$。接下来一行$n$个正整数$c_1, c_2, \dots, c_n(1\leq c_i\leq 10^9)$。

保证$\sum n\leq 10^6$。
 

Output
对于每组数据,输出两个数,分别表示最大最小的和。
 

Sample Input
1 6 4 2 1 2 3 4 5 6
 

Sample Output
15 10
 

Hint

一个可行的方案为 3, 4, 6, 5, 2, 1 和 5, 3, 2, 1, 6, 4。
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-18 12:11:05, Gzip enabled