Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 155 ms):
t=int(input())

for i in range(t):
    n,l,r=list(map(int,input().split()))
    l-=1
    a=list(map(int,input().split()))
    b=a[:l]+sorted(a[l:])
    c=sorted(a[:r])[::-1]+a[r:]
    print(min(sum(c[l:r]),sum(b[l:r])))



Solution 2 (runtime: 296 ms):
standard_input, packages, output_together = 1, 1, 0

dfs, hashing, read_from_file = 1, 1, 0

de = 1

 

if 1:

 

    if standard_input:

        import io, os, sys

        input = lambda: sys.stdin.readline().strip()

 

        import math

        inf = math.inf

 

        def I():

            return input()

        

        def II():

            return int(input())

 

        def MII():

            return map(int, input().split())

 

        def LI():

            return list(input().split())

 

        def LII():

            return list(map(int, input().split()))

 

        def LFI():

            return list(map(float, input().split()))

 

        def GMI():

            return map(lambda x: int(x) - 1, input().split())

 

        def LGMI():

            return list(map(lambda x: int(x) - 1, input().split()))

 

    if packages:

        from io import BytesIO, IOBase

 

        import random

        import os

 

        import bisect

        import typing

        from collections import Counter, defaultdict, deque

        from copy import deepcopy

        from functools import cmp_to_key, lru_cache, reduce

        from heapq import merge, heapify, heappop, heappush, heappushpop, nlargest, nsmallest

        from itertools import accumulate, combinations, permutations, count, product

        from operator import add, iand, ior, itemgetter, mul, xor

        from string import ascii_lowercase, ascii_uppercase, ascii_letters

        from typing import *

        BUFSIZE = 4096

 

    if output_together:

        class FastIO(IOBase):

            newlines = 0

 

            def __init__(self, file):

                self._fd = file.fileno()

                self.buffer = BytesIO()

                self.writable = "x" in file.mode or "r" not in file.mode

                self.write = self.buffer.write if self.writable else None

 

            def read(self):

                while True:

                    b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))

                    if not b:

                        break

                    ptr = self.buffer.tell()

                    self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)

                self.newlines = 0

                return self.buffer.read()

 

            def readline(self):

                while self.newlines == 0:

                    b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))

                    self.newlines = b.count(b"\n") + (not b)

                    ptr = self.buffer.tell()

                    self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)

                self.newlines -= 1

                return self.buffer.readline()

 

            def flush(self):

                if self.writable:

                    os.write(self._fd, self.buffer.getvalue())

                    self.buffer.truncate(0), self.buffer.seek(0)

 

        class IOWrapper(IOBase):

            def __init__(self, file):

                self.buffer = FastIO(file)

                self.flush = self.buffer.flush

                self.writable = self.buffer.writable

                self.write = lambda s: self.buffer.write(s.encode("ascii"))

                self.read = lambda: self.buffer.read().decode("ascii")

                self.readline = lambda: self.buffer.readline().decode("ascii")

 

        sys.stdout = IOWrapper(sys.stdout)

 

    if dfs:

        from types import GeneratorType

 

        def bootstrap(f, stk=[]):

            def wrappedfunc(*args, **kwargs):

                if stk:

                    return f(*args, **kwargs)

                else:

                    to = f(*args, **kwargs)

                    while True:

                        if type(to) is GeneratorType:

                            stk.append(to)

                            to = next(to)

                        else:

                            stk.pop()

                            if not stk:

                                break

                            to = stk[-1].send(to)

                    return to

            return wrappedfunc

 

    if hashing:

        RANDOM = random.getrandbits(20)

        class Wrapper(int):

            def __init__(self, x):

                int.__init__(x)



            def __eq__(self, other):

                # print(f"Comparing {self.value} with {other}")

                if isinstance(other, Wrapper):

                    return self.value == other.value

                return self.value == other  # 允许与普通数值比较

            

            def __hash__(self):

                return super(Wrapper, self).__hash__() ^ RANDOM

 

    if read_from_file:

        file = open("input.txt", "r", encoding='utf-16').readline().strip()

        fin = open(file, 'r')

        input = lambda: fin.readline().strip()

        output_file = open("output.txt", "w")

        def fprint(*args, **kwargs):

            print(*args, **kwargs, file=output_file)

 

    if de:

        def debug(*args, **kwargs):

            print('\033[92m', end='')

            print(*args, **kwargs)

            print('\033[0m', end='')

 

    fmax = lambda x, y: x if x > y else y

    fmin = lambda x, y: x if x < y else y

 

    class lst_lst:

        def __init__(self, n) -> None:

            self.n = n

            self.pre = []

            self.cur = []

            self.lst = [-1] * n

        

        def append(self, i, j):

            self.pre.append(self.lst[i])

            self.lst[i] = len(self.cur)

            self.cur.append(j)

        

        def iterate(self, i):

            tmp = self.lst[i]

            while tmp != -1:

                yield self.cur[tmp]

                tmp = self.pre[tmp]



#Solution

def f(l1,l2):

    res = sum(l1)

    for i in range(fmin(len(l1), len(l2))):

        if l1[i] > l2[i]:

            res -= l1[i] - l2[i]

        else:

            break

    return res

def solve():

    l1, l2, l3 = [], [], []

    for i in range(n):

        if i < l:

            l1.append(A[i])

        elif i <= r:

            l3.append(A[i])

        else:

            l2.append(A[i])

    L = [inf] * (n+1)

    l1.sort()

    l2.sort()

    l3.sort(reverse = True)

    L[0] = 0

    res = fmin(f(l3, l2), f(l3, l1))

    return res

    pass

    

if __name__ == '__main__':

    t = II()

    for _ in range(t):

        #IO

        n, l, r = MII()

        l -= 1

        r -= 1

        A = LII()

        print(solve())

        # print(' '.join(map(str, solve())))