Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;



// Function to compute the Greatest Common Divisor (GCD)

ll gcd(ll x, ll y) {

    return y == 0 ? x : gcd(y, x % y);

}



// Function to compute the Least Common Multiple (LCM)

ll lcm(ll x, ll y) {

    return (x / gcd(x, y)) * y;

}

vector<int>gra[100];

void solve(int n,int m)

{

    vector<int>v(n+1,0);

    for(int i = 0;i<m;i++)

    {

        int x,y;

        cin>> x >> y;

        v[x]++,v[y]++;

    }

    int cen = 0, cnted=0;

    for(int i = 1;i<=n;i++)

    {

        if(v[i]==1)cnted++;

        else if(v[i]==m)cen++;

    }

    if(cen==1&&cnted==n-1)

    {

        cout << "star topology";

        return ;

    }

    bool bus = (m==n-1);

    int one = 0;

    int two = 0;

    for(int i= 1;i<=n;i++)

    {

        if(v[i]==1)one++;

        else if(v[i]==2)two++;

        else

        {

            bus = false;

            break;

        }

    }

    if(one==2&& two==n-2&& bus)

    {

        cout << "bus topology";

        return ;

    }

    bool ring = (n==m);

    for(int i = 1;i<=n;i++)

    {

        if(v[i]!=2)

        {

            ring = false;

            break;



        }



    }

    if(ring)

    {

        cout << "ring topology ";

        return ;

    }

    cout << "unknown topology ";



}



int main() {



    int t;

    cin >>  t;

    while(t--)

    {

        int n,l,r;

        cin>> n >> l >> r;

        vector<int>a(n);

        for(int &i:a)cin>>i;

        l--;

        vector<int>temp(a.begin(),a.begin()+r);

        sort(temp.begin(),temp.end());

        vector<int>z(a.begin()+l,a.end());

        sort(z.begin(),z.end());

        int sum1 = accumulate(temp.begin(),temp.begin()+r-l,0);

        int sum2 = accumulate(z.begin(),z.begin()+r-l,0);

        cout << min(sum1,sum2)<< endl;



    }







    return 0;

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// Function to compute the Greatest Common Divisor (GCD)
ll gcd(ll x, ll y) {
    return y == 0 ? x : gcd(y, x % y);
}

// Function to compute the Least Common Multiple (LCM)
ll lcm(ll x, ll y) {
    return (x / gcd(x, y)) * y;
}
vector<int>gra[100];
void solve(int n,int m)
{
    vector<int>v(n+1,0);
    for(int i = 0;i<m;i++)
    {
        int x,y;
        cin>> x >> y;
        v[x]++,v[y]++;
    }
    int cen = 0, cnted=0;
    for(int i = 1;i<=n;i++)
    {
        if(v[i]==1)cnted++;
        else if(v[i]==m)cen++;
    }
    if(cen==1&&cnted==n-1)
    {
        cout << "star topology";
        return ;
    }
    bool bus = (m==n-1);
    int one = 0;
    int two = 0;
    for(int i= 1;i<=n;i++)
    {
        if(v[i]==1)one++;
        else if(v[i]==2)two++;
        else
        {
            bus = false;
            break;
        }
    }
    if(one==2&& two==n-2&& bus)
    {
        cout << "bus topology";
        return ;
    }
    bool ring = (n==m);
    for(int i = 1;i<=n;i++)
    {
        if(v[i]!=2)
        {
            ring = false;
            break;

        }

    }
    if(ring)
    {
        cout << "ring topology ";
        return ;
    }
    cout << "unknown topology ";

}

int main() {

    int t;
    cin >>  t;
    while(t--)
    {
        int n,l,r;
        cin>> n >> l >> r;
        vector<int>a(n);
        for(int &i:a)cin>>i;
        l--;
        vector<int>temp(a.begin(),a.begin()+r);
        sort(temp.begin(),temp.end());
        vector<int>z(a.begin()+l,a.end());
        sort(z.begin(),z.end());
        ll sum1 = accumulate(temp.begin(),temp.begin()+r-l,0LL);
        ll sum2 = accumulate(z.begin(),z.begin()+r-l,0LL);
        cout << min(sum1,sum2)<< endl;

    }



    return 0;
}