Problem: 2063B - Subsequence Update
Language: C# 10

Previous submission (verdict: Wrong answer on test 2):
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int t = int.Parse(Console.ReadLine()); // 读取测试用例数量
        while (t-- > 0)
        {
            string[] input = Console.ReadLine().Split();
            int n = int.Parse(input[0]); // 序列长度
            int l = int.Parse(input[1]); // 区间左端点
            int r = int.Parse(input[2]); // 区间右端点

            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); // 读取序列

            // 计算区间 [l, r] 内的最小和
            long minSum = GetMinSumAfterReversingSubsequence(a, l - 1, r - 1, n - 1); // 转换为 0-based 索引
            Console.WriteLine(minSum);
        }
    }

    static long GetMinSumAfterReversingSubsequence(int[] a, int l, int r, int n)
    {
        // 区间 [l, r] 内的元素
        int[] inside = new int[r-l+1];
        Array.Sort(inside);
        Array.Copy(a, l, inside, 0, inside.Length);
        long asum = 0;
        long lsum = 0;
        long rsum = 0;
        long ans = 0;

        if(l > 0) {
            int[] lseg = new int[l];
            Array.Copy(a, 0, lseg, 0, lseg.Length);
            Array.Sort(lseg);
            for(int i = 0; i < lseg.Length && i < inside.Length; i++){
                asum += inside[inside.Length-i-1];
                lsum += lseg[i];
                if(lsum < asum){
                    ans = Math.Min(ans, lsum - asum);
                }
            }
        }
        asum = 0;
        if(n > r){
            int[] rseg = new int[n-r];
            Array.Copy(a, r+1, rseg, 0, rseg.Length);
            Array.Sort(rseg);
            for(int i = 0; i < rseg.Length && i < inside.Length; i++){
                asum += inside[inside.Length-i-1];
                rsum += rseg[i];
                if(rsum < asum){
                    ans = Math.Min(ans, rsum - asum);
                }
            }
        }
        
        for(int i = 0; i < inside.Length; i++){
            ans += inside[i];
        }

        return ans;
    }
}

Submission (verdict: Accepted):
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int t = int.Parse(Console.ReadLine()); // 读取测试用例数量
        while (t-- > 0)
        {
            string[] input = Console.ReadLine().Split();
            int n = int.Parse(input[0]); // 序列长度
            int l = int.Parse(input[1]); // 区间左端点
            int r = int.Parse(input[2]); // 区间右端点

            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); // 读取序列

            // 计算区间 [l, r] 内的最小和
            long minSum = GetMinSumAfterReversingSubsequence(a, l - 1, r - 1, n - 1); // 转换为 0-based 索引
            Console.WriteLine(minSum);
        }
    }

    static long GetMinSumAfterReversingSubsequence(int[] a, int l, int r, int n)
    {
        // 区间 [l, r] 内的元素
        int[] inside = new int[r-l+1];
        Array.Copy(a, l, inside, 0, inside.Length);
        Array.Sort(inside);
        long asum = 0;
        long lsum = 0;
        long rsum = 0;
        long ans = 0;

        if(l > 0) {
            int[] lseg = new int[l];
            Array.Copy(a, 0, lseg, 0, lseg.Length);
            Array.Sort(lseg);
            for(int i = 0; i < lseg.Length && i < inside.Length; i++){
                asum += inside[inside.Length-i-1];
                lsum += lseg[i];
                if(lsum < asum){
                    ans = Math.Min(ans, lsum - asum);
                }
            }
        }
        asum = 0;
        if(n > r){
            int[] rseg = new int[n-r];
            Array.Copy(a, r+1, rseg, 0, rseg.Length);
            Array.Sort(rseg);
            for(int i = 0; i < rseg.Length && i < inside.Length; i++){
                asum += inside[inside.Length-i-1];
                rsum += rseg[i];
                if(rsum < asum){
                    ans = Math.Min(ans, rsum - asum);
                }
            }
        }
        
        for(int i = 0; i < inside.Length; i++){
            ans += inside[i];
        }

        return ans;
    }
}