ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,k; cin>>n>>k;
    set<int> s;
    unordered_map<int, int> freq;
    for(int i = 0;i < n; ++i)
    {
        int x; cin>>x;
        s.insert(x);
        freq[x]++;
    }

    vector<int> freqarr;
    for(auto it: freq)
    {
        if(it.second)
            freqarr.push_back(it.second);
    }
    sort(freqarr.begin(), freqarr.end());

    int cnt = 0;
    for(int i= 0; i < freqarr.size()-1; ++i)
    {
        if(k >= freqarr[i]) 
        {
            ++cnt;
            k -= freqarr[i];
        }
        else break;
    }
    // cout << cnt << endl;
    cout << (int)s.size() -cnt << endl;
    
   



    // adjust k times

    // remove the minimum elements of a subarray

    //  2 1 3 2 1 1 


    // count freq
    // 1, 4
    // 2, 2
    // 4, 3 
    // 5, 1
}
int main()
{
    int t; cin>>t;for(int i = 0; i < t; ++i) solve();
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,k; cin>>n>>k;
    set<int> s;
    unordered_map<int, int> freq;
    for(int i = 0;i < n; ++i)
    {
        int x; cin>>x;
        s.insert(x);
        freq[x]++;
    }

    vector<int> freqarr;
    for(auto it: freq)
    {
        if(it.second)
            freqarr.push_back(it.second);
    }
    sort(freqarr.begin(), freqarr.end());

    int cnt = 0;
    for(int i= 0; i < freqarr.size()-1; ++i)
    {
        if(k >= freqarr[i]) 
        {
            ++cnt;
            k -= freqarr[i];
        }
        else break;
    }
    // cout << cnt << endl;
    cout << (int)s.size() -cnt << endl;
    
   



    // adjust k times

    // remove the minimum elements of a subarray

    //  2 1 3 2 1 1 


    // count freq
    // 1, 4
    // 2, 2
    // 4, 3 
    // 5, 1
}
int main()
{
    int t; cin>>t;for(int i = 0; i < t; ++i) solve();
}

Submission (verdict: Time limit exceeded on test 20):
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,k; cin>>n>>k;
    set<int> s;
    unordered_map<int, int> freq;
    for(int i = 0;i < n; ++i)
    {
        int x; cin>>x;
        s.insert(x);
        freq[x]++;
    }

    vector<int> freqarr;
    for(auto it: freq)
    {
       freqarr.push_back(it.second);
    }
    sort(freqarr.begin(), freqarr.end());

    int cnt = 0;
    for(int i= 0; i < freqarr.size()-1; ++i)
    {
        if(k >= freqarr[i]) 
        {
            ++cnt;
            k -= freqarr[i];
        }
        else break;
    }
    // cout << cnt << endl;
    cout << (int)s.size() -cnt << endl;
    
   



    // adjust k times

    // remove the minimum elements of a subarray

    //  2 1 3 2 1 1 


    // count freq
    // 1, 4
    // 2, 2
    // 4, 3 
    // 5, 1
}
int main()
{
    int t; cin>>t;for(int i = 0; i < t; ++i) solve();
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 20):
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,k; cin>>n>>k;
    set<int> s;
    unordered_map<int, int> freq;
    for(int i = 0;i < n; ++i)
    {
        int x; cin>>x;
        s.insert(x);
        freq[x]++;
    }

    vector<int> freqarr;
    for(auto it: freq)
    {
       freqarr.push_back(it.second);
    }
    sort(freqarr.begin(), freqarr.end());

    int cnt = 0;
    for(int i= 0; i < freqarr.size()-1; ++i)
    {
        if(k >= freqarr[i]) 
        {
            ++cnt;
            k -= freqarr[i];
        }
        else break;
    }
    // cout << cnt << endl;
    cout << (int)s.size() -cnt << endl;
    
   



    // adjust k times

    // remove the minimum elements of a subarray

    //  2 1 3 2 1 1 


    // count freq
    // 1, 4
    // 2, 2
    // 4, 3 
    // 5, 1
}
int main()
{
    int t; cin>>t;for(int i = 0; i < t; ++i) solve();
}

Submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,k; cin>>n>>k;
    
    unordered_map<int, int> freq;
    for(int i = 0;i < n; ++i)
    {
        int x; cin>>x;
        freq[x]++;
    }

    vector<int> freqarr;
    for(auto it: freq)
    {
       freqarr.push_back(it.second);
    }
    sort(freqarr.begin(), freqarr.end());

    int cnt = 0;
    for(int i= 0; i < freqarr.size()-1; ++i)
    {
        if(k >= freqarr[i]) 
        {
            ++cnt;
            k -= freqarr[i];
        }
        else break;
    }
    // cout << cnt << endl;
    cout << (int)freq.size() -cnt << endl;
    
   



    // adjust k times

    // remove the minimum elements of a subarray

    //  2 1 3 2 1 1 


    // count freq
    // 1, 4
    // 2, 2
    // 4, 3 
    // 5, 1
}
int main()
{
    int t; cin>>t;for(int i = 0; i < t; ++i) solve();
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,k; cin>>n>>k;
    
    unordered_map<int, int> freq;
    for(int i = 0;i < n; ++i)
    {
        int x; cin>>x;
        freq[x]++;
    }

    vector<int> freqarr;
    for(auto it: freq)
    {
       freqarr.push_back(it.second);
    }
    sort(freqarr.begin(), freqarr.end());

    int cnt = 0;
    for(int i= 0; i < freqarr.size()-1; ++i)
    {
        if(k >= freqarr[i]) 
        {
            ++cnt;
            k -= freqarr[i];
        }
        else break;
    }
    // cout << cnt << endl;
    cout << (int)freq.size() -cnt << endl;
    
   



    // adjust k times

    // remove the minimum elements of a subarray

    //  2 1 3 2 1 1 


    // count freq
    // 1, 4
    // 2, 2
    // 4, 3 
    // 5, 1
}
int main()
{
    int t; cin>>t;for(int i = 0; i < t; ++i) solve();
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,k; cin>>n>>k;
    
    vector<int> arr(n);
    for(int i = 0; i < n; ++i) cin>>arr[i];
    sort(arr.begin(), arr.end());

    int l = 0, r  = 0;
    // 1 1 2 2 2
    priority_queue<int, vector<int>, greater<int>> s;
    while(l < n)
    {
        while(r < n && arr[r] == arr[l]) ++r;
        s.push((r-l));
        l = r;
        // ++cnt; 
    }
    // cout << s.size() << endl;
    
    while(s.size() > 1)
    {
        auto it = s.top();
        if(it <= k) 
        {
            k -= it;
            s.pop();
        }
        else break;
    }
    // while(s.size())
    // {
    //     cout << s.top() << ' ';
    //     s.pop();
    // }
    // cout << endl;
   cout << s.size()<< endl;
    
   



    // adjust k times

    // remove the minimum elements of a subarray

    //  2 1 3 2 1 1 


    // count freq
    // 1, 4
    // 2, 2
    // 4, 3 
    // 5, 1
}
int main()
{
    int t; cin>>t;for(int i = 0; i < t; ++i) solve();
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
#define _F ""
using namespace std;
typedef long long ll;

constexpr int maxn = 2e5 + 5;
int n, m, b[maxn];
multiset<int> a;

void input()
{
    cin>>n>>m;
    a.clear();
    int x;
    for (int i = 1; i <= n; ++i)
    {
        cin>>x;
        a.insert(x);
    }
    for (int i = 1; i <= m; ++i) cin>>b[i];
    sort(b+1, b+m+1);
}

void solve()
{
    for (int i = 1; i <= m; ++i)
    {
        if (*a.begin() > b[i])
        {
            cout<<"NO\n";
            return;
        }
        else if (*a.begin() == b[i]) a.erase(a.begin());
        else
        {
            auto it = next(a.begin(), 1);
            int v = *it + *a.begin();
            if (it == a.end() || *it - *a.begin() > 1)
            {
                cout<<"NO\n";
                return;
            }
            a.erase(it); a.erase(a.begin());
            a.insert(v);
            --i;
        }
    }
    cout<<(a.empty() ? "YES\n" : "NO\n");
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(_F".INP", "r"))
    {
        freopen(_F".INP", "r", stdin);
        freopen(_F".OUT", "w", stdout);
    }
    int t = 1; cin>>t;
    while (t--)
    {
        input();
        solve();
    }
}


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define _F ""
using namespace std;
typedef long long ll;

constexpr int maxn = 2e5 + 5;
int n, m, b[maxn];
multiset<int> a;

void input()
{
    cin>>n>>m;
    a.clear();
    int x;
    for (int i = 1; i <= n; ++i)
    {
        cin>>x;
        a.insert(x);
    }
    for (int i = 1; i <= m; ++i) cin>>b[i];
    sort(b+1, b+m+1);
}

void solve()
{
    for (int i = 1; i <= m; ++i)
    {
        if (a.empty() || *a.begin() > b[i])
        {
            cout<<"NO\n";
            return;
        }
        else if (*a.begin() == b[i]) a.erase(a.begin());
        else
        {
            auto it = next(a.begin(), 1);
            int v = *it + *a.begin();
            if (it == a.end() || *it - *a.begin() > 1)
            {
                cout<<"NO\n";
                return;
            }
            a.erase(it); a.erase(a.begin());
            a.insert(v);
            --i;
        }
    }
    cout<<(a.empty() ? "YES\n" : "NO\n");
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(_F".INP", "r"))
    {
        freopen(_F".INP", "r", stdin);
        freopen(_F".OUT", "w", stdout);
    }
    int t = 1; cin>>t;
    while (t--)
    {
        input();
        solve();
    }
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define _F ""
using namespace std;
typedef long long ll;

constexpr int maxn = 2e5 + 5;
int n, m, b[maxn];
multiset<int> a;

void input()
{
    cin>>n>>m;
    a.clear();
    int x;
    for (int i = 1; i <= n; ++i)
    {
        cin>>x;
        a.insert(x);
    }
    for (int i = 1; i <= m; ++i) cin>>b[i];
    sort(b+1, b+m+1);
}

void solve()
{
    for (int i = 1; i <= m; ++i)
    {
        if (a.empty() || *a.begin() > b[i])
        {
            cout<<"NO\n";
            return;
        }
        else if (*a.begin() == b[i]) a.erase(a.begin());
        else
        {
            auto it = next(a.begin(), 1);
            int v = *it + *a.begin();
            if (it == a.end() || *it - *a.begin() > 1)
            {
                cout<<"NO\n";
                return;
            }
            a.erase(it); a.erase(a.begin());
            a.insert(v);
            --i;
        }
    }
    cout<<(a.empty() ? "YES\n" : "NO\n");
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(_F".INP", "r"))
    {
        freopen(_F".INP", "r", stdin);
        freopen(_F".OUT", "w", stdout);
    }
    int t = 1; cin>>t;
    while (t--)
    {
        input();
        solve();
    }
}


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

constexpr int maxn = 2e5 + 5;
int n, m;
multiset<int> a, b;

void input()
{
    cin>>n>>m;
    a.clear(), b.clear();
    int x;
    for (int i = 1; i <= n; ++i)
    {
        cin>>x;
        a.insert(x);
    }
    for (int i = 1; i <= m; ++i)
    {
        cin>>x;
        b.insert(x);
    }
}

void solve()
{
    while (!a.empty() || !b.empty())
    {
        if (*a.begin() > *b.begin() || b.size() > a.size())
        {
            cout<<"NO\n";
            return;
        }
        else if (*a.begin() == *b.begin())
        {
            a.erase(a.begin());
            b.erase(b.begin());
        }
        else
        {
            int v = *b.begin();
            auto it = a.lower_bound(v);
            b.erase(b.begin());
            if (it != a.end() && *it == v)
            {
                a.erase(it);
                continue;
            }
            b.insert(v/2), b.insert(v - v/2);
        }
    }
    cout<<(a.empty() && b.empty() ? "YES\n" : "NO\n");
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(_F".INP", "r"))
    {
        freopen(_F".INP", "r", stdin);
        freopen(_F".OUT", "w", stdout);
    }
    int t = 1; cin>>t;
    while (t--)
    {
        input();
        solve();
    }
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
#define _F ""
using namespace std;
typedef long long ll;

constexpr int maxn = 2e5 + 5;
int n, m, b[maxn];
multiset<int> a;

void input()
{
    cin>>n>>m;
    a.clear();
    int x;
    for (int i = 1; i <= n; ++i)
    {
        cin>>x;
        a.insert(x);
    }
    for (int i = 1; i <= m; ++i) cin>>b[i];
    sort(b+1, b+m+1);
}

void solve()
{
    for (int i = 1; i <= m; ++i)
    {
        if (*a.begin() > b[i])
        {
            cout<<"NO\n";
            return;
        }
        else if (*a.begin() == b[i]) a.erase(a.begin());
        else
        {
            auto it = next(a.begin(), 1);
            int v = *it + *a.begin();
            if (it == a.end() || *it - *a.begin() > 1)
            {
                cout<<"NO\n";
                return;
            }
            a.erase(it); a.erase(a.begin());
            a.insert(v);
            --i;
        }
    }
    cout<<(a.empty() ? "YES\n" : "NO\n");
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(_F".INP", "r"))
    {
        freopen(_F".INP", "r", stdin);
        freopen(_F".OUT", "w", stdout);
    }
    int t = 1; cin>>t;
    while (t--)
    {
        input();
        solve();
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pair<int,int>> vp_int;
typedef vector<vector<int>> vii;
typedef vector<long long> vlong;
typedef vector<vector<long long>> vlonglong;
typedef long long ll;
typedef vector<pair<ll,ll>> vp_ll;
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define nl cout<<"\n"
#define MOD 1000000007
#define no cout<<"NO\n"
#define yes cout<<"YES\n"

ll binexp(ll a, ll n,ll M) {
    if (n == 0) return 1LL;
    if (n % 2) {
        ll temp = binexp(a, (n - 1) / 2,M);
        return ((a * temp)%M * temp)%M;
    }
    ll q = binexp(a, n / 2,M);
    return (q * q)%M;
}
ll lcm(ll a,ll b) {return a*(b/__gcd(a,b));}
ll pmmi(ll a,ll M) {return binexp(a,M-2,M);}

ll msb(ll n) {ll ans=-1;while(n){ans++;n=n>>1;}return ans;}
ll lsb(ll n){for(ll i=0;i<64;i++){if(n&(1<<i)) return i;}return -1;}

// bitcomplement till msb only
// for 1's complement use ~
ll bitcomplement(ll n){return n^((1<<(msb(n)+1))-1);}

void solve() {
    ll n;cin>>n;
    vlong arr(n);
    for(auto &i:arr){
        cin>>i;i--;
    }
    
    vp_ll swap;
    vlong ans(n);
    for(ll i=0;i<n;i++) ans[i]=i;
    for(ll i=0;i<n;i++){
        ll j=i;
        while(ans[j]!=arr[i]) j++;
        
        j++;
        while(j<n){
            swap.pb({ans[j],arr[i]});
            j++;
        }
        
        for(ll k=n-1;k>=i;k--){
            if(ans[k]==arr[i]) continue;
            swap.pb({arr[i],ans[k]});
        }
        
        

        j=i+1;
        while(j<n && ans[j]!=arr[i]){
            ans[j]=ans[j-1];j++;
        }
        ans[j]=ans[j-1];
        ans[i]=arr[i];
    }
    cout<<swap.size()<<"\n";
    for(auto &i:swap) cout<<i.first+1<<" "<<i.second+1<<"\n";
    
    
}

int main() {
#ifndef ONLINE_JUDGE
    clock_t START = clock();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {solve();}

#ifndef ONLINE_JUDGE
    cout << "\nTime : " << ((float)(clock() - START)) / CLOCKS_PER_SEC << " sec\n";
#endif

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code();
#include<bits/stdc++.h>
#define ll long long 
#define read(x) int x;cin>>x;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vb vector<bool>
#define ld long double 
using namespace std;

void init_code(){
	#ifndef ONLINE_JUDGE
	freopen("inputf.txt","r",stdin);
	freopen("outputf.txt","w",stdout);
	#endif
}

int solve2(int pos, vvl &edges,int n){
	int maxi = INT_MIN;
	for (int i=0;i<n;i++){
		if (i == pos)continue;
		bool p = false;
		for (int j=0;j<edges[i].size();j++){
			if (pos == edges[i][j]){
				p = true;
				break;
			}
		}
		int sz = edges[i].size()-p;
		maxi = max(maxi,sz);
	}

	return maxi ;
}

ll max(ll a , ll b){
	if (a>b)return a;
	return b;
}

void solve(){
	ll n; cin >>n;
	ll sum =0;
	vl arr(n);
	for (int i=0;i<n;i++){
		cin>>arr[i];
		sum += arr[i];
	}
	if (n==1 and arr[0] < 0){
		cout <<arr[0]<<endl;
		return ;
	}
	for (int i=0;i<n-1;i++){
		for (int j=0;j<n-1-i;j++){
			arr[j] = arr[j]-arr[j+1];
		}
	}
	cout <<max(sum,abs(arr[0]))<<endl;

}

int main(){
	fast ;
	read(t);
	while (t--)solve();
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code();
#include<bits/stdc++.h>
#define ll long long 
#define read(x) int x;cin>>x;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vb vector<bool>
#define ld long double 
using namespace std;

void init_code(){
	#ifndef ONLINE_JUDGE
	freopen("inputf.txt","r",stdin);
	freopen("outputf.txt","w",stdout);
	#endif
}

int solve2(int pos, vvl &edges,int n){
	int maxi = INT_MIN;
	for (int i=0;i<n;i++){
		if (i == pos)continue;
		bool p = false;
		for (int j=0;j<edges[i].size();j++){
			if (pos == edges[i][j]){
				p = true;
				break;
			}
		}
		int sz = edges[i].size()-p;
		maxi = max(maxi,sz);
	}

	return maxi ;
}

ll max(ll a , ll b){
	if (a>b)return a;
	return b;
}

void solve(){
	ll n; cin >>n;
	ll sum =0;
	vl arr(n);
	for (int i=0;i<n;i++){
		cin>>arr[i];
		sum += arr[i];
	}
	if (n==1 and arr[0] < 0){
		cout <<arr[0]<<endl;
		return ;
	}
	for (int i=0;i<n-1;i++){
		for (int j=0;j<n-1-i;j++){
			arr[j] = arr[j]-arr[j+1];
		}
	}
	cout <<max(sum,abs(arr[0]))<<endl;

}

int main(){
	fast ;
	read(t);
	while (t--)solve();
	return 0;
}



Submission (verdict: Wrong answer on test 2):
#include <iostream>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code();
#include<bits/stdc++.h>
#define ll long long 
#define read(x) int x;cin>>x;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vb vector<bool>
#define ld long double 
#define vld vector<ld>
using namespace std;

void init_code(){
	#ifndef ONLINE_JUDGE
	freopen("inputf.txt","r",stdin);
	freopen("outputf.txt","w",stdout);
	#endif
}

int solve2(int pos, vvl &edges,int n){
	int maxi = INT_MIN;
	for (int i=0;i<n;i++){
		if (i == pos)continue;
		bool p = false;
		for (int j=0;j<edges[i].size();j++){
			if (pos == edges[i][j]){
				p = true;
				break;
			}
		}
		int sz = edges[i].size()-p;
		maxi = max(maxi,sz);
	}

	return maxi ;
}

ld max(ld a , ld b){
	if (a>b)return a;
	return b;
}

void solve(){
	ld n; cin >>n;
	ld sum =0;
	vld arr(n);
	for (int i=0;i<n;i++){
		cin>>arr[i];
		sum += arr[i];
	}
	if (n==1 and arr[0] < 0){
		cout <<arr[0]<<endl;
		return ;
	}
	for (int i=0;i<n-1;i++){
		for (int j=0;j<n-1-i;j++){
			arr[j] = arr[j]-arr[j+1];
		}
	}
	cout <<max(sum,abs(arr[0]))<<endl;

}

int main(){
	fast ;
	read(t);
	while (t--)solve();
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code();
#include<bits/stdc++.h>
#define ll long long 
#define read(x) int x;cin>>x;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vb vector<bool>
#define ld long double 
#define vld vector<ld>
using namespace std;

void init_code(){
	#ifndef ONLINE_JUDGE
	freopen("inputf.txt","r",stdin);
	freopen("outputf.txt","w",stdout);
	#endif
}

int solve2(int pos, vvl &edges,int n){
	int maxi = INT_MIN;
	for (int i=0;i<n;i++){
		if (i == pos)continue;
		bool p = false;
		for (int j=0;j<edges[i].size();j++){
			if (pos == edges[i][j]){
				p = true;
				break;
			}
		}
		int sz = edges[i].size()-p;
		maxi = max(maxi,sz);
	}

	return maxi ;
}

ld max(ld a , ld b){
	if (a>b)return a;
	return b;
}

void solve(){
	ld n; cin >>n;
	ld sum =0;
	vld arr(n);
	for (int i=0;i<n;i++){
		cin>>arr[i];
		sum += arr[i];
	}
	if (n==1 and arr[0] < 0){
		cout <<arr[0]<<endl;
		return ;
	}
	for (int i=0;i<n-1;i++){
		for (int j=0;j<n-1-i;j++){
			arr[j] = arr[j]-arr[j+1];
		}
	}
	cout <<max(sum,abs(arr[0]))<<endl;

}

int main(){
	fast ;
	read(t);
	while (t--)solve();
	return 0;
}



Submission (verdict: Accepted):
#include <iostream>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code();
#include<bits/stdc++.h>
#define ll long long 
#define read(x) int x;cin>>x;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vb vector<bool>
#define ld long double 
using namespace std;

void init_code(){
	#ifndef ONLINE_JUDGE
	freopen("inputf.txt","r",stdin);
	freopen("outputf.txt","w",stdout);
	#endif
}

ll min(ll a, ll b){
	if (a<b)return a;
	return b;
}

ll max(ll a, ll b){
	if (a>b)return a;
	return b;
}

void solve(){
	ll n ; cin >> n;
	vl arr(n);
	ll sum =0;
	for (int i=0;i<n;i++){cin>>arr[i];sum+=arr[i];}
	if (n==1){
		cout <<arr[0]<<endl;
		return ;
	}
	for (int i=0;i<n-1;i++){
		ll s =0;
		for (int j=0;j<n-1-i;j++){
			arr[j] = arr[j]-arr[j+1];
			s+=arr[j];
		}
		sum = max(abs(s),sum);
	}
	cout <<sum<<endl;
}

int main(){
	fast ;
	read(t);
	while (t--)solve();
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

#define endl '\n'
#define int long long

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--;
    r--;
    int a[n];
    for (int &i : a)
        cin >> i;
    sort(a, a + l);
    sort(a + l, a + r + 1);
    sort(a + r + 1, a + n);
    int ans = 0;
    for (int i = l; i <= r; i++) {
        ans += a[i];
    }
    int left = ans;
    for (int i = 0; i < l && i <= r && a[i] < a[r - i]; i++) {
        left += a[i] - a[r - i];
    }
    int right = ans;
    for (int i = 0; i + r + 1 < n && i <= r && a[i + r + 1] < a[r - i]; i++) {
        right += a[i + r + 1] - a[r - i];
    }
    cout << min(left, right) << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define int long long

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--;
    r--;
    int a[n];
    for (int &i : a)
        cin >> i;
    sort(a, a + l);
    sort(a + l, a + r + 1);
    sort(a + r + 1, a + n);
    int ans = 0;
    for (int i = l; i <= r; i++) {
        ans += a[i];
    }
    int left = ans;
    for (int i = 0; l <= r - i && i < l && a[i] < a[r - i]; i++) {
        left += a[i] - a[r - i];
    }
    int right = ans;
    for (int i = 0; l <= r - i && i + r + 1 < n && a[i + r + 1] < a[r - i];
         i++) {
        right += a[i + r + 1] - a[r - i];
    }
    cout << min(left, right) << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
}