ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 280 ms):
from itertools import accumulate, pairwise
import math
import bisect
import heapq
from collections import Counter, defaultdict
from functools import cache
def solve():
    n, l, r = map(int, input().split())
    arr = [int(x) for x in input().split()]
    # 
    if l == 1 or r == n or r - l == 0:
        arr.sort()
        print(sum(arr[: r - l + 1]))
    else:
        first = arr[:r]
        second = arr[l - 1:]
        first.sort()
        second.sort()
        print(min(sum(first[: r - l + 1]), sum(second[: r - l + 1])))
for _ in range(int(input())):
    solve()
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 437 ms):
for _ in range(int(input())):

    n , l , r= [int(num) for num in input().split()]

    nums= [int(num) for num in input().split()]

    left = sum(sorted(nums[:r])[:r-l+1])

    right = sum(sorted(nums[l-1:])[:r-l+1])

    print(min(left,right))
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 155 ms):

for _ in range(int(input())):
	n,l,r = list(map(int,input().split(" ")))
	a = list(map(int,input().split(" ")))
	left = sorted(a[:r])
	right = sorted(a[l-1:])
	print(min(sum(left[:r-l+1]),sum(right[:r-l+1])))
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 374 ms):
for _ in range(int(input())):
    n,l,r=map(int,input().split())
    l-=1
    r-=1
    a=list(map(int,input().split()))
    if l==0 and r==n-1:
        print(sum(a[l:r+1]))
        continue
    if l==r:
        print(min(a))
        continue
    sub,subleft,subright,t,res=sorted(a[l:r+1],reverse=True),sorted(a[:l]),sorted(a[r+1:]),sum(a[l:r+1]),float('inf')
    if l>0:
        change=0
        for i in range(r-l+1):
            if i<len(subleft):
                if subleft[i]<sub[i]:
                    change+=subleft[i]-sub[i]
            else:
                break
        res=min(res,t+change)
    if r<n:
        change=0
        for i in range(r-l+1):
            if i<len(subright):
                if subright[i]<sub[i]:
                    change+=subright[i]-sub[i]
            else:
                break
        res=min(res,t+change)
    print(res)
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 375 ms):
inp = lambda: int(input())
minp = lambda: map(int, input().split())
linp = lambda: list(map(int, input().split()))
tinp = lambda: tuple(map(int, input().split()))
import math

def solve():
    n, l, r = minp()
    left = []
    mid = []
    right = []
    for i, v in enumerate(minp()):
        if i < l-1:
            left.append(v)
        elif i < r:
            mid.append(v)
        else:
            right.append(v)
    left.sort()
    mid.sort()
    right.sort()
    
    ans1 = ans2 = sum(mid)
    a = 0
    b = len(mid)-1
    while a < len(left) and b >= 0 and left[a] < mid[b]:
        ans1 -= mid[b]-left[a]
        a+=1; b-=1
    a = 0
    b = len(mid)-1
    while a < len(right) and b >= 0 and right[a] < mid[b]:
        ans2 -= mid[b]-right[a]
        a+=1; b-=1
    
    print(min(ans1, ans2))

    
        

for _ in range(inp()):
    solve()
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 312 ms):
t=int(input())

for case in range(t):

    s=0

    n,l,r=map(int,input().split())

    seq=list(map(int,input().split()))

    a=seq[:l-1]+sorted(seq[l-1:])

    b=sorted(seq[:r])[::-1]+seq[r:]

    print(min(sum(a[l-1:r]),sum(b[l-1:r])))
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 327 ms):
############ ---- Functions for inputs ---- ############
import math
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter

def number(): return (int(input()))
def numbers(): return (map(int, input().split()))
def array(): return (list(map(int, input().split())))
def string(): return input()
############ ---- Functions for inputs ---- ############

t = number()

for _ in range(t):
  n, l, r = numbers()
  nums = array()
  left = nums[:l - 1]
  right = nums[r:]
  middle = nums[l - 1:r]
  option1 = sorted(left + middle)
  option2 = sorted(right + middle)
  print(min(sum(option1[:r - l + 1]), sum(option2[:r - l + 1])))
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 140 ms):
for i in range(int(input())):

    n,l,r = map(int,input().split())

    a = list(map(int,input().split()))

    l-=1

    r-=1

    l1 = a[l:]

    l2 = a[:r+1]

    l1.sort()

    l2.sort()

    print(min(sum(l1[:r-l+1]),sum(l2[:r-l+1])))
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 390 ms):
for _ in range(int(input())):
    n, l, r = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    
    lst1 = sorted(a[0:l - 1])
    lst2 = sorted(a[l - 1:r], reverse = True)
    if r < n:
        lst3 = sorted(a[r:])
    else:
        lst3 = []
    
    res = sum(lst2)
    for i in range(min(len(lst1), len(lst2))):
        if lst1[i] < lst2[i]:
            res += (lst1[i] - lst2[i])
        else:
            break
    
    res1 = sum(lst2)
    for i in range(min(len(lst3), len(lst2))):
        if lst3[i] < lst2[i]:
            res1 += (lst3[i] - lst2[i])
        else:
            break
    
    print(min(res, res1))
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 358 ms):
from collections import defaultdict, Counter
from random import randint
def intlist(): return list(map(int, (x for x in input().split())))


def check(mid, portion):
    mid = sorted(mid)[::-1]
    portion.sort()
    su = 0
    len_mid = len(mid)
    len_portion = len(portion)
    i, j = 0, 0
    while j < len_mid and i < len_portion:
        if mid[j] <= portion[i]:
            break 
        su += portion[i]
        i += 1
        j += 1
    while j < len_mid:
        su += mid[j]
        j += 1
    return su


for _ in range(int(input())):
    n, l, r = intlist()
    nums = intlist()
    first = nums[:l-1]
    mid = nums[l-1:r]
    last = nums[r:]
    print(min(check(mid, first), check(mid, last)))
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 139 ms):
t=int(input())

for _ in range(t):

    n,l,r=map(int,input().split())

    a=list(map(int,input().split()))

    l=l-1

    r=r-1

    l1=a[:r+1]

    l2=a[l:]

    l1.sort()

    l2.sort()

    print(min(sum(l1[:r-l+1]),sum(l2[:r-l+1])))
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 156 ms):
t = int(input())

 

for i in range(t):

    [n, l, r] = [int(val) for val in input().split()]

    nums = [int(val) for val in input().split()]

    nums_one = [int(val) for val in nums[:r]]

    nums_two = [int(val) for val in nums[l-1:]]

    nums_one.sort()

    nums_two.sort()

    print(min(sum(nums_one[:r-l+1]), sum(nums_two[:r-l+1])))

    # ret = 0

    # for j in range(r-l+1):

    #     ret_one += nums[j]

    # print(ret)
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 343 ms):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  segment.sort()

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < len(left) and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  segment.sort()

  i, j = 0, len(segment) - 1

  while i < (len(right)) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())
Problem: 2063B - Subsequence Update
Language: python

Solution 1 (runtime: 218 ms):
n = int(input())
for i in range(n):
    data = input().split(" ")
    arr = input().split(" ")
    arrint = [int(i) for i in arr]
    dataint = [int(i) for i in data]
    dataint[1] -= 1
    dataint[2] -= 1
    left = []
    mid = []
    right = []
    for v in range(dataint[0]):
        if v < dataint[1]:
            left += [arrint[v]]
        if v >= dataint[1] and v <= dataint[2]:
            mid += [arrint[v]]
        if v > dataint[2]:
            right += [arrint[v]]
    lsort = sorted(left)
    msort = sorted(mid, reverse = True)
    rsort = sorted(right)
    count = 0
    while count < min(len(lsort),len(msort)) and lsort[count] < msort[count]:
        lsort[count] , msort[count] =  msort[count], lsort[count]
        count += 1
    
    minimum = sum(msort)

    count = 0

    msort = sorted(mid, reverse = True)
    while count < min(len(rsort),len(msort)) and rsort[count] < msort[count]:
        rsort[count] , msort[count] =  msort[count], rsort[count]
        count += 1
    
    minimum = min(minimum, sum(msort))
    print(minimum)

    




Solution 2 (runtime: 171 ms):
t = int(input())

for _ in range(t):

    n,l,r = map(int,input().split())

    arr = list(map(int,input().split()))

   



    l-=1

    brr=arr[:l]+sorted(arr[l:])

    crr=sorted(arr[:r])[::-1]+arr[r:]

    print(min(sum(brr[l:r]),sum(crr[l:r])))