ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
bool b[200005];
int main(){
	int t;cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i];
		if(a[1]>a[2]){cout<<"NO\n";continue;}
		for(int i=1;i<=n;i++)b[i]=0;b[n]=1;
		for(int i=n-1;i>=1;i--){
			if(a[i]<=a[i+1])b[i]=1;else break;}
		bool ok=0;
		for(int i=2;i<n;i++){
			int now=min(a[i],a[i-1]);
			a[i]-=now;a[i-1]-=now;
			if(a[i]<a[i+1]&&b[i+1]){ok=1;break;}
			if(a[i]>a[i+1])break;}
		if(ok)cout<<"YES"<<endl;
		else cout<<"No"<<endl;
	
	
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
bool b[200005];
int main(){
	int t;cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i];
		if(a[1]>a[2]){cout<<"NO\n";continue;}
		for(int i=1;i<=n;i++)b[i]=0;b[n]=1;
		for(int i=n-1;i>=1;i--){
			if(a[i]<=a[i+1])b[i]=1;else break;}
		bool ok=0;
		if(b[1])ok=1;
		for(int i=2;i<n;i++){
			int now=min(a[i],a[i-1]);
			a[i]-=now;a[i-1]-=now;
			if(a[i]<=a[i+1]&&b[i+1]){ok=1;break;}
			if(a[i]>a[i+1])break;}
		if(ok)cout<<"YES"<<endl;
		else cout<<"No"<<endl;
	
	
	}
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
bool b[200005];
int main(){
	int t;cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i];
		if(a[1]>a[2]){cout<<"NO\n";continue;}
		for(int i=1;i<=n;i++)b[i]=0;b[n]=1;
		for(int i=n;i>=1;i--){
			if(a[i]<=a[i+1])b[i]=1;else break;}
		bool ok=0;
		for(int i=2;i<n;i++){
			if(a[i]<a[i+1]&&b[i+1]){ok=1;break;}
			int now=min(a[i],a[i-1]);
			a[i]-=now;a[i-1]-=now;}
		if(ok)cout<<"YES"<<endl;
		else cout<<"No"<<endl;
	
	
	}
	return 0;
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
bool b[200005];
int main(){
	int t;cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i];
		if(a[1]>a[2]){cout<<"NO\n";continue;}
		for(int i=1;i<=n;i++)b[i]=0;b[n]=1;
		for(int i=n;i>=1;i--){
			if(a[i]<=a[i+1])b[i]=1;else break;}
		bool ok=0;
		for(int i=2;i<n;i++){
			if(a[i]<a[i+1]&&b[i+1]){ok=1;break;}
			int now=min(a[i],a[i-1]);
			a[i]-=now;a[i-1]-=now;
			if(a[i]<a[i+1]&&b[i+1]){ok=1;break;}}
		if(ok)cout<<"YES"<<endl;
		else cout<<"No"<<endl;
	
	
	}
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
bool b[200005];
int main(){
	int t;cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i];
		if(a[1]>a[2]){cout<<"NO\n";continue;}
		for(int i=1;i<=n;i++)b[i]=0;b[n]=1;
		for(int i=n;i>=1;i--){
			if(a[i]<=a[i+1])b[i]=1;else break;}
		bool ok=0;
		for(int i=2;i<n;i++){
			if(a[i]<a[i+1]&&b[i+1]){ok=1;break;}
			int now=min(a[i],a[i-1]);
			a[i]-=now;a[i-1]-=now;}
		if(ok)cout<<"YES"<<endl;
		else cout<<"No"<<endl;
	
	
	}
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
bool b[200005];
int main(){
	int t;cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i];
		if(a[1]>a[2]){cout<<"NO\n";continue;}
		for(int i=1;i<=n;i++)b[i]=0;b[n]=1;
		for(int i=n;i>=1;i--){
			if(a[i]<=a[i+1])b[i]=1;else break;}
		bool ok=0;
		for(int i=2;i<n;i++){
			if(a[i]<a[i+1]&&b[i+1]){ok=1;break;}
			int now=min(a[i],a[i-1]);
			a[i]-=now;a[i-1]-=now;
			if(a[i]<a[i+1]&&b[i+1]){ok=1;break;}}
		if(ok)cout<<"YES"<<endl;
		else cout<<"No"<<endl;
	
	
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
bool b[200005];
int main(){
	int t;cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i];
		if(a[1]>a[2]){cout<<"NO\n";continue;}
		for(int i=1;i<=n;i++)b[i]=0;b[n]=1;
		for(int i=n-1;i>=1;i--){
			if(a[i]<=a[i+1])b[i]=1;else break;}
		bool ok=0;
		for(int i=2;i<n;i++){
			int now=min(a[i],a[i-1]);
			a[i]-=now;a[i-1]-=now;
			if(a[i]<a[i+1]&&b[i+1]){ok=1;break;}
			if(a[i]>a[i+1])break;}
		if(ok)cout<<"YES"<<endl;
		else cout<<"No"<<endl;
	
	
	}
	return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 7):
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

bool match_and_del(multiset<int>& a, multiset<int>& b) {
    bool del_st = false;
    queue<int> del_queue;
    for(auto& val : b) {
        auto ia = a.find(val);
        if(ia != a.end()) {
            del_queue.push(val);
        }
    }

    while(!del_queue.empty()) {
        int val = del_queue.front(); del_queue.pop();
        // cout << "del " << val << endl;
        auto ia = a.find(val);
        auto ib = b.find(val);
        if(ia != a.end()) {
            a.erase(ia);
            b.erase(ib);
            del_st = true;
        }
    }

    return del_st;
}


int main() {
    int kase;
    cin >> kase;

    while(kase--) {
        int n, m;
        cin >> n >> m;
        
        int x;
        multiset<int> a, b;
        for(int i = 0; i < n; i++) {
            cin >> x;
            a.insert(x);
        }
        for(int i = 0; i < m; i++) {
            cin >> x;
            b.insert(x);
        }
        
        match_and_del(a, b);
        while(!a.empty() && !b.empty()) {
            int x = *b.rbegin();
            bool new_split = false;
            if(x > 1) {
                b.erase(b.find(x));
                // cout << "split " << x << " into " << x/2 << " and " << x-x/2 << endl;
                b.insert(x/2); b.insert(x-x/2);    
                new_split = true;
            }
            
            bool del_st = match_and_del(a, b);
            if(!new_split && !del_st) break;
            if(b.size() > a.size()) break;
        }

        if(a.empty() && b.empty()) cout << "YES" << endl;
        else cout << "NO" << endl;

    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 1):
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

int main() {
    int kase;
    cin >> kase;

    while(kase--) {
        int n, m;
        cin >> n >> m;
        
        int x;
        multiset<int> a, b;
        for(int i = 0; i < n; i++) {
            cin >> x;
            a.insert(x);
        }
        for(int i = 0; i < m; i++) {
            cin >> x;
            b.insert(x);
        }
        
        while(!a.empty() and !b.empty()) {
            int largest = *b.rbegin();
            b.erase(b.find(largest));

            auto ia = a.find(largest);
            if(ia != a.end()) {
                a.erase(ia);
            }
            else {
                if(largest == 1) {
                    break;
                }

                b.insert(x/2);
                b.insert(x-x/2);
            }
        }

        if(a.empty() && b.empty()) cout << "YES" << endl;
        else cout << "NO" << endl;

    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 1):
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

int main() {
    int kase;
    cin >> kase;

    while(kase--) {
        int n, m;
        cin >> n >> m;
        
        int x;
        multiset<int> a, b;
        for(int i = 0; i < n; i++) {
            cin >> x;
            a.insert(x);
        }
        for(int i = 0; i < m; i++) {
            cin >> x;
            b.insert(x);
        }
        
        while(!a.empty() and !b.empty()) {
            int largest = *b.rbegin();
            b.erase(b.find(largest));

            auto ia = a.find(largest);
            if(ia != a.end()) {
                a.erase(ia);
            }
            else {
                if(largest == 1) {
                    break;
                }

                b.insert(x/2);
                b.insert(x-x/2);
            }
        }

        if(a.empty() && b.empty()) cout << "YES" << endl;
        else cout << "NO" << endl;

    }
    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

int main() {
    int kase;
    cin >> kase;

    while(kase--) {
        int n, m;
        cin >> n >> m;
        
        int x;
        multiset<int> a, b;
        for(int i = 0; i < n; i++) {
            cin >> x;
            a.insert(x);
        }
        for(int i = 0; i < m; i++) {
            cin >> x;
            b.insert(x);
        }
        
        while(!a.empty() and !b.empty()) {
            int largest = *b.rbegin();
            // cout << "Check " << largest << endl;
            b.erase(b.find(largest));

            auto ia = a.find(largest);
            if(ia != a.end()) {
                a.erase(ia);
            }
            else {
                if(largest == 1) {
                    break;
                }
                // cout << "Split into " << largest/2 << " and " << largest-largest/2 << endl;
                b.insert(largest/2);
                b.insert(largest-largest/2);
            }
            if(b.size() > a.size()) break;
        }

        if(a.empty() && b.empty()) cout << "YES" << endl;
        else cout << "NO" << endl;

    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 2):
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

void match_and_del(multiset<int>& a, multiset<int>& b) {
    queue<int> del_queue;
    for(auto& val : b) {
        auto ia = a.find(val);
        if(ia != a.end()) {
            del_queue.push(val);
        }
    }

    while(!del_queue.empty()) {
        int val = del_queue.front(); del_queue.pop();
        auto ia = a.find(val);
        auto ib = b.find(val);
        if(ia != a.end()) {
            a.erase(ia);
            b.erase(ib);
        }
    }
}


int main() {
    int kase;
    cin >> kase;

    while(kase--) {
        int n, m;
        cin >> n >> m;
        
        int x;
        multiset<int> a, b;
        for(int i = 0; i < n; i++) {
            cin >> x;
            a.insert(x);
        }
        for(int i = 0; i < m; i++) {
            cin >> x;
            b.insert(x);
        }
        match_and_del(a, b);

        while(!a.empty() && !b.empty()) {
            int x = *b.rbegin();
            if(x > 1) {
                b.erase(b.find(x));
                // cout << "split " << x << " into " << x/2 << " and " << x-x/2 << endl;
                b.insert(x/2); b.insert(x-x/2);    
            }
            
            match_and_del(a, b);

            if(b.size() > a.size()) break;
        }

        if(a.empty() && b.empty()) cout << "YES" << endl;
        else cout << "NO" << endl;

    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <stack>
#include <numeric>
#define ll long long
#define getarray int n; std::cin >> n; auto arr = new int[n]; for (int i = 0; i < n; i++) std::cin >> arr[i];

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(nullptr);
	int times;
	std::cin >> times;
	while (times--) {
		int n; std::cin >> n;
		auto arr = new ll[n];
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> arr[i];
			sum += arr[i];
		}
		if (n == 1) {
			std::cout << arr[0] << "\n";
			continue;
		}
		int index = 1;
		//std::cout << sum << "\n";
		while (index < n) {
			sum = std::max(sum, std::abs(arr[index] - arr[n - 1]));
			for (int i = n - 1; i >= index; i--) arr[i] -= arr[i - 1];
			index++;
		}
		sum = std::max(sum, std::abs(arr[index] - arr[n - 1]));
		std::cout << std::max(sum, std::abs(arr[n - 1])) << "\n";
	}
}




Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <stack>
#include <numeric>
#define ll long long
#define getarray int n; std::cin >> n; auto arr = new int[n]; for (int i = 0; i < n; i++) std::cin >> arr[i];

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(nullptr);
	int times;
	std::cin >> times;
	while (times--) {
		int n; std::cin >> n;
		auto arr = new ll[n];
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> arr[i];
			sum += arr[i];
		}
		if (n == 1) {
			std::cout << arr[0] << "\n";
			continue;
		}
		int index = 0;
		//std::cout << sum << "\n";
		while (index < n) {
			sum = std::max(sum, std::abs(arr[index] - arr[n - 1]));
			for (int i = n - 1; i > index; i--) arr[i] -= arr[i - 1];
			index++;
		}
		std::cout << std::max(sum, std::abs(arr[n - 1])) << "\n";
	}
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <stack>
#include <numeric>
#define ll long long
#define getarray int n; std::cin >> n; auto arr = new int[n]; for (int i = 0; i < n; i++) std::cin >> arr[i];

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(nullptr);
	int times;
	std::cin >> times;
	while (times--) {
		int n; std::cin >> n; 
		auto arr = new int[n]; 
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> arr[i];
			sum += arr[i];
		}
		if (n == 1) {
			std::cout << arr[0] << "\n";
			continue;
		}
		int index = 1;
		//std::cout << sum << "\n";
		while (index<n) {
			for (int i = n - 1; i >= index; i--) arr[i] -= arr[i - 1];
			sum = std::max(sum, (ll)std::abs(arr[index] - arr[n - 1]));
			/*std::cout << sum << "\n";
			for (int i = index; i < n; i++) std::cout << arr[i] << " ";
			std::cout << "\n";*/
			index++;
		}
		std::cout << std::max(sum, (ll)std::abs(arr[n - 1])) << "\n";
	}
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <stack>
#include <numeric>
#define ll long long
#define getarray int n; std::cin >> n; auto arr = new int[n]; for (int i = 0; i < n; i++) std::cin >> arr[i];

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(nullptr);
	int times;
	std::cin >> times;
	while (times--) {
		int n; std::cin >> n; 
		auto arr = new int[n]; 
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> arr[i];
			sum += arr[i];
		}
		if (n == 1) {
			std::cout << arr[0] << "\n";
			continue;
		}
		int index = 1;
		//std::cout << sum << "\n";
		while (index<n) {
			for (int i = n - 1; i >= index; i--) arr[i] -= arr[i - 1];
			sum = std::max(sum, (ll)std::abs(arr[index] - arr[n - 1]));
			/*std::cout << sum << "\n";
			for (int i = index; i < n; i++) std::cout << arr[i] << " ";
			std::cout << "\n";*/
			index++;
		}
		std::cout << std::max(sum, (ll)std::abs(arr[n - 1])) << "\n";
	}
}




Submission (verdict: Wrong answer on test 6):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <stack>
#include <numeric>
#define ll long long
#define getarray int n; std::cin >> n; auto arr = new int[n]; for (int i = 0; i < n; i++) std::cin >> arr[i];

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(nullptr);
	int times;
	std::cin >> times;
	while (times--) {
		int n; std::cin >> n; 
		auto arr = new ll[n]; 
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> arr[i];
			sum += arr[i];
		}
		if (n == 1) {
			std::cout << arr[0] << "\n";
			continue;
		}
		int index = 1;
		//std::cout << sum << "\n";
		while (index<n) {
			for (int i = n - 1; i >= index; i--) arr[i] -= arr[i - 1];
			sum = std::max(sum, std::abs(arr[index] - arr[n - 1]));
			/*std::cout << "<" << sum << ">\n";
			for (int i = index; i < n; i++) std::cout << arr[i] << " ";
			std::cout << "\n";*/
			index++;
		}
		std::cout << std::max(sum, std::abs(arr[n - 1])) << "\n";
	}
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 6):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <stack>
#include <numeric>
#define ll long long
#define getarray int n; std::cin >> n; auto arr = new int[n]; for (int i = 0; i < n; i++) std::cin >> arr[i];

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(nullptr);
	int times;
	std::cin >> times;
	while (times--) {
		int n; std::cin >> n; 
		auto arr = new ll[n]; 
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> arr[i];
			sum += arr[i];
		}
		if (n == 1) {
			std::cout << arr[0] << "\n";
			continue;
		}
		int index = 1;
		//std::cout << sum << "\n";
		while (index<n) {
			for (int i = n - 1; i >= index; i--) arr[i] -= arr[i - 1];
			sum = std::max(sum, std::abs(arr[index] - arr[n - 1]));
			/*std::cout << "<" << sum << ">\n";
			for (int i = index; i < n; i++) std::cout << arr[i] << " ";
			std::cout << "\n";*/
			index++;
		}
		std::cout << std::max(sum, std::abs(arr[n - 1])) << "\n";
	}
}




Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <stack>
#include <numeric>
#define ll long long
#define getarray int n; std::cin >> n; auto arr = new int[n]; for (int i = 0; i < n; i++) std::cin >> arr[i];

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(nullptr);
	int times;
	std::cin >> times;
	while (times--) {
		int n; std::cin >> n; 
		auto arr = new ll[n]; 
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> arr[i];
			sum += arr[i];
		}
		if (n == 1) {
			std::cout << arr[0] << "\n";
			continue;
		}
		int index = 1;
		
		//std::cout << sum << "\n";
		while (index<n) {
			//std::cout << sum << " ";
			sum = std::max(sum, std::abs(arr[index] - arr[n - 1]));
			//std::cout << sum << "\n";
			for (int i = n - 1; i >= index; i--) arr[i] -= arr[i - 1];
			/*std::cout << "<" << std::abs(arr[index] - arr[n - 1]) << ">\n";
			for (int i = index; i < n; i++) std::cout << arr[i] << " ";
			std::cout << "\n";*/
			index++;
		}
		std::cout << std::max(sum, std::abs(arr[n - 1])) << "\n";
	}
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <stack>
#include <numeric>
#define ll long long
#define getarray int n; std::cin >> n; auto arr = new int[n]; for (int i = 0; i < n; i++) std::cin >> arr[i];

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(nullptr);
	int times;
	std::cin >> times;
	while (times--) {
		int n; std::cin >> n; 
		auto arr = new ll[n]; 
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> arr[i];
			sum += arr[i];
		}
		if (n == 1) {
			std::cout << arr[0] << "\n";
			continue;
		}
		int index = 1;
		
		//std::cout << sum << "\n";
		while (index<n) {
			//std::cout << sum << " ";
			sum = std::max(sum, std::abs(arr[index] - arr[n - 1]));
			//std::cout << sum << "\n";
			for (int i = n - 1; i >= index; i--) arr[i] -= arr[i - 1];
			/*std::cout << "<" << std::abs(arr[index] - arr[n - 1]) << ">\n";
			for (int i = index; i < n; i++) std::cout << arr[i] << " ";
			std::cout << "\n";*/
			index++;
		}
		std::cout << std::max(sum, std::abs(arr[n - 1])) << "\n";
	}
}




Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <stack>
#include <numeric>
#define ll long long
#define getarray int n; std::cin >> n; auto arr = new int[n]; for (int i = 0; i < n; i++) std::cin >> arr[i];

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(nullptr);
	int times;
	std::cin >> times;
	while (times--) {
		int n; std::cin >> n;
		auto arr = new ll[n];
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> arr[i];
			sum += arr[i];
		}
		if (n == 1) {
			std::cout << arr[0] << "\n";
			continue;
		}
		int index = 1;
		//std::cout << sum << "\n";
		while (index < n) {
			sum = std::max(sum, std::abs(arr[index] - arr[n - 1]));
			for (int i = n - 1; i >= index; i--) arr[i] -= arr[i - 1];
			index++;
		}
		sum = std::max(sum, std::abs(arr[index] - arr[n - 1]));
		std::cout << std::max(sum, std::abs(arr[n - 1])) << "\n";
	}
}
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;

typedef long long ll;

void solve() {
	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);
	unordered_map<ll, ll> um;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		um[x[i]]++;
	}
	if (k == n) {
		cout << "1\n";
		return;
	}
	vector<pair<ll, ll>> v(um.begin(), um.end());
	sort(v.begin(), v.end(), [](pair<ll, ll> &a, pair<ll, ll>& b) {
		return a.second < b.second;
	});
	int i = 0;
	while (k > 0) {
		ll ele = v[i].first;
		ll freq = v[i].second;
		if (freq <= k) {
			k -= freq;
			v[i].second = 0;
		}
		else break;
		++i;
	}
	ll res = 0;
	for (ll i = 0; i < v.size(); i++) {
		if (v[i].second > 0) ++res;
	}
	cout << res << "\n";
}

int main() {
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

void solve() {
	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	if (k == n) {
		cout << "1\n";
		return;
	}
	sort(x.begin(), x.end());
	vector<pair<ll, ll>> v;
	for (ll i = 0; i < n; i++) {
		if (v.empty() || v.back().first != x[i]) v.push_back({x[i], 1});
		else v.back().second++;
	}

	sort(v.begin(), v.end(), [](pair<ll, ll> &a, pair<ll, ll>& b) {
		return a.second < b.second;
	});
	ll i = 0, res = 0;
	while (k > 0 || i < v.size()) {
		ll ele = v[i].first;
		ll freq = v[i].second;
		if (freq <= k) {
			k -= freq;
			v[i].second = 0;
		}
		else {
			++res;
		}
		++i;
	}
	// ll res = 0;
	// for (ll i = 0; i < v.size(); i++) {
	// 	if (v[i].second > 0) ++res;
	// }
	cout << res << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}