ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
//the template
#include <iostream>
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for (int i = a; (i) < (b); (i)++)
#define revrange(i, a, b) for (int i = a; (i) >= (b); (i)--)
using namespace std;
vector<int> *adj;
void solve(){
	int n;
	cin>>n;
	adj = new vector<int>[n];
	
	range(i,0,n-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	vector<pair<int,int>> p(n);
	range(i,0,n)
	p[i] = make_pair(i,adj[i].size());
	/*range(i,0,n)
	cout<<p[i].second<<" ";*/
	int mx1_node = -1;
	int mx1 = -1;
	range(i,0,n){
		if(p[i].second>mx1){
		mx1 = p[i].second;
		mx1_node = p[i].first;
	}
	else
	continue;}
	for(int i : adj[mx1_node])
	p[i].second--;
	int mx2 = -1;
	
	range(i,0,n){
		if(i!=mx1_node){
		if(p[i].second>mx2)
		mx2 = p[i].second;}
	}
	if(mx2 == 0)
	cout<<mx1-1<<endl;
	else if(mx2 == 1)
	cout<<mx1<<endl;
	else
	cout<<mx1+mx2 - 1<<endl;
}
int32_t main(){
	int t;
	cin>>t;
	while(t--)
	solve();
}

Submission (verdict: Accepted):
//the template
#include <iostream>
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for (int i = a; (i) < (b); (i)++)
#define revrange(i, a, b) for (int i = a; (i) >= (b); (i)--)
using namespace std;
vector<int> *adj;
void solve(){
	int n;
	cin>>n;
	adj = new vector<int>[n];
	
	range(i,0,n-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	vector<pair<int,int>> p(n);
	range(i,0,n)
	p[i] = make_pair(i,adj[i].size());
	/*range(i,0,n)
	cout<<p[i].second<<" ";*/
	int mx1_node = -1;
	int mx1 = -1;
	range(i,0,n){
		if(p[i].second>mx1){
		mx1 = p[i].second;
		mx1_node = p[i].first;
	}
	}
	int alt = -1;
	range(i,0,n){
	if(p[i].second == mx1 && p[i].first!=mx1_node)
	alt = i;
	}
	for(int i : adj[mx1_node])
	p[i].second--;
	
	int mx2 = -1;
	
	range(i,0,n){
		if(i!=mx1_node){
		if(p[i].second>mx2)
		mx2 = p[i].second;}
	}
	for(int i : adj[mx1_node])
	p[i].second++;
	if(alt!=-1){
	for(int i : adj[alt])
	p[i].second--;}
	
	int alt2 = -1;
	if(alt!=-1){
	range(i,0,n){
		if(i!=alt){
		if(p[i].second>alt2)
		alt2 = p[i].second;}
	}
	}
    if(alt == -1)
    cout<<mx1+mx2-1<<endl;
	else
	cout<<max(mx1 + mx2 - 1, mx1 + alt2 - 1)<<endl;
	
}
int32_t main(){
	int t;
	cin>>t;
	while(t--)
	solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
//the template
#include <iostream>
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for (int i = a; (i) < (b); (i)++)
#define revrange(i, a, b) for (int i = a; (i) >= (b); (i)--)
using namespace std;
vector<int> *adj;
void solve(){
	int n;
	cin>>n;
	adj = new vector<int>[n];
	
	range(i,0,n-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	vector<pair<int,int>> p(n);
	range(i,0,n)
	p[i] = make_pair(i,adj[i].size());
	/*range(i,0,n)
	cout<<p[i].second<<" ";*/
	int mx1_node = -1;
	int mx1 = -1;
	range(i,0,n){
		if(p[i].second>mx1){
		mx1 = p[i].second;
		mx1_node = p[i].first;
	}
	else
	continue;}
	for(int i : adj[mx1_node])
	p[i].second--;
	int mx2 = -1;
	
	range(i,0,n){
		if(i!=mx1_node){
		if(p[i].second>mx2)
		mx2 = p[i].second;}
	}
	if(mx2 == 0)
	cout<<mx1-1<<endl;
	else
	cout<<mx1+mx2 - 1<<endl;
}
int32_t main(){
	int t;
	cin>>t;
	while(t--)
	solve();
}

Submission (verdict: Wrong answer on test 2):
//the template
#include <iostream>
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for (int i = a; (i) < (b); (i)++)
#define revrange(i, a, b) for (int i = a; (i) >= (b); (i)--)
using namespace std;
vector<int> *adj;
void solve(){
	int n;
	cin>>n;
	adj = new vector<int>[n];
	
	range(i,0,n-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	vector<pair<int,int>> p(n);
	range(i,0,n)
	p[i] = make_pair(i,adj[i].size());
	/*range(i,0,n)
	cout<<p[i].second<<" ";*/
	int mx1_node = -1;
	int mx1 = -1;
	range(i,0,n){
		if(p[i].second>mx1){
		mx1 = p[i].second;
		mx1_node = p[i].first;
	}
	else
	continue;}
	for(int i : adj[mx1_node])
	p[i].second--;
	int mx2 = -1;
	
	range(i,0,n){
		if(i!=mx1_node){
		if(p[i].second>mx2)
		mx2 = p[i].second;}
	}
	if(mx2 == 0)
	cout<<mx1-1<<endl;
	else if(mx2 == 1)
	cout<<mx1<<endl;
	else
	cout<<mx1+mx2 - 1<<endl;
}
int32_t main(){
	int t;
	cin>>t;
	while(t--)
	solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
//the template
#include <iostream>
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for (int i = a; (i) < (b); (i)++)
#define revrange(i, a, b) for (int i = a; (i) >= (b); (i)--)
using namespace std;
vector<int> *adj;
void solve(){
	int n;
	cin>>n;
	adj = new vector<int>[n];
	
	range(i,0,n-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	vector<pair<int,int>> p(n);
	range(i,0,n)
	p[i] = make_pair(i,adj[i].size());
	/*range(i,0,n)
	cout<<p[i].second<<" ";*/
	int mx1_node = -1;
	int mx1 = -1;
	range(i,0,n){
		if(p[i].second>mx1){
		mx1 = p[i].second;
		mx1_node = p[i].first;
	}
	else
	continue;}
	for(int i : adj[mx1_node])
	p[i].second--;
	int mx2 = -1;
	
	range(i,0,n){
		if(i!=mx1_node){
		if(p[i].second>mx2)
		mx2 = p[i].second;}
	}
	if(mx2 == 0)
	cout<<mx1-1<<endl;
	else
	cout<<mx1+mx2 - 1<<endl;
}
int32_t main(){
	int t;
	cin>>t;
	while(t--)
	solve();
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

typedef long long ll;
#define pb push_back

string solve(int n) {
	vector<int> arr(n);

	for(int j = 0; j<n; j++) {
		cin >> arr[j];
	}

	if(arr[1] < arr[0]) return "NO";
	for(int j = 1; j<n; j++) {
		if(arr[j] < arr[j-1]) {
			arr[j-1] -= arr[j-2];
			arr[j-2] = 0;

			if(arr[j] < arr[j-1]) return "NO";
		}
	}

	return "YES";
}

int main() {
    ios::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

	int tc;
	cin >> tc;

	while(tc--) {
		int n;
		cin >> n;

		cout << solve(n) << "\n";
	}

	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back

string solve(int n) {
	vector<int> arr(n);

	for(int j = 0; j<n; j++) {
		cin >> arr[j];
	}

	if(arr[1] < arr[0]) return "NO";
	for(int j = 0; j<n-1; j++) {
		// if(arr[j+1] < arr[j]) return "NO";
		arr[j+1] -= arr[j];
		arr[j] = 0;
	}

	for(int j = 1; j<n; j++) {
		if(arr[j] < arr[j-1]) return "NO";
	}

	return "YES";
}

int main() {
    ios::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

	int tc;
	cin >> tc;

	while(tc--) {
		int n;
		cin >> n;

		cout << solve(n) << "\n";
	}

	return 0;
}

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

typedef long long ll;
#define pb push_back

string solve(int n) {
	vector<int> arr(n);

	for(int j = 0; j<n; j++) {
		cin >> arr[j];
	}

	if(arr[1] < arr[0]) return "NO";
	for(int j = 0; j<n-1; j++) {
		if(arr[j+1] < arr[j]) return "NO";
		arr[j+1] -= arr[j];
		arr[j] = 0;
	}

	for(int j = 1; j<n; j++) {
		// cout << arr[j] << " ";
		if(arr[j] < arr[j-1]) return "NO";
	}

	return "YES";
}

int main() {
    ios::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

	int tc;
	cin >> tc;

	while(tc--) {
		int n;
		cin >> n;

		cout << solve(n) << "\n";
	}

	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

typedef long long ll;
#define pb push_back

string solve(int n) {
	vector<int> arr(n);

	for(int j = 0; j<n; j++) {
		cin >> arr[j];
	}

	if(arr[1] < arr[0]) return "NO";
	for(int j = 1; j<n; j++) {
		if(arr[j] < arr[j-1]) {
			arr[j-1] -= arr[j-2];
			arr[j-2] = 0;

			if(arr[j] < arr[j-1]) return "NO";
		}
	}

	return "YES";
}

int main() {
    ios::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

	int tc;
	cin >> tc;

	while(tc--) {
		int n;
		cin >> n;

		cout << solve(n) << "\n";
	}

	return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back

string solve(int n) {
	vector<int> arr(n);

	for(int j = 0; j<n; j++) {
		cin >> arr[j];
	}

	if(arr[1] < arr[0]) return "NO";
	for(int j = 0; j<n-1; j++) {
		// if(arr[j+1] < arr[j]) return "NO";
		arr[j+1] -= arr[j];
		arr[j] = 0;
	}

	for(int j = 1; j<n; j++) {
		if(arr[j] < arr[j-1]) return "NO";
	}

	return "YES";
}

int main() {
    ios::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

	int tc;
	cin >> tc;

	while(tc--) {
		int n;
		cin >> n;

		cout << solve(n) << "\n";
	}

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

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf (1LL<<60)
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
 
int main() {
   init_code();
   int t;
   cin >> t;
   while(t--){
         int n;
         cin>>n;

         int arr[n];
         for(int i=0;i<n;i++){
            cin>>arr[i];
         }
         if(n==1){
            cout<<arr[0]<<endl;
            continue;
         }
         int j=n;
         int max_sum=-100000;

         while(j>0){
            int sum=0;
            for(int i=0;i<j;i++){
               sum+=arr[i];
            }
            max_sum=max(max_sum,abs(sum));
            int k=0;
            for(int i=1;i<j;i++){
               arr[k++]=arr[i]-arr[i-1];
            }
            j--;

         }
         cout<<max_sum<<endl;


   }
   return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf (1LL<<60)
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
 
int main() {
   init_code();
   int t;
   cin >> t;
   while(t--){
         int n;
         cin>>n;

         int arr[n];
         for(int i=0;i<n;i++){
            cin>>arr[i];
         }
         
         int j=n;
         int max_sum=0;
         for(int i=0;i<n;i++){
            max_sum+=arr[i];
         }
         if(n>1){
               while(j>0){
               int sum=0;
               for(int i=0;i<j;i++){
                  sum+=arr[i];
               }
               max_sum=max(max_sum,abs(sum));
               int k=0;
               for(int i=1;i<j;i++){
                  arr[k++]=arr[i]-arr[i-1];
               }
               j--;

            }
         }
         
         cout<<max_sum<<endl;


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


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf (1LL<<60)
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
 
int main() {
   init_code();
   int t;
   cin >> t;
   while(t--){
         int n;
         cin>>n;

         int arr[n];
         for(int i=0;i<n;i++){
            cin>>arr[i];
         }
         if(n==1){
            cout<<arr[0]<<endl;
            continue;
         }
         int j=n;
         int max_sum=-100000;

         while(j>0){
            int sum=0;
            for(int i=0;i<j;i++){
               sum+=arr[i];
            }
            max_sum=max(max_sum,abs(sum));
            int k=0;
            for(int i=1;i<j;i++){
               arr[k++]=arr[i]-arr[i-1];
            }
            j--;

         }
         cout<<max_sum<<endl;


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

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf (1LL<<60)
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
 
int main() {
   init_code();
   int t;
   cin >> t;
   while(t--){
         int n;
         cin>>n;

         int arr[n];
         for(int i=0;i<n;i++){
            cin>>arr[i];
         }
         
         int j=n;
         int max_sum=0;
         for(int i=0;i<n;i++){
            max_sum+=arr[i];
         }
         if(n>1){
               while(j>0){
               int sum=0;
               for(int i=0;i<j;i++){
                  sum+=arr[i];
               }
               max_sum=max(max_sum,abs(sum));
               int k=0;
               for(int i=1;i<j;i++){
                  arr[k++]=arr[i]-arr[i-1];
               }
               j--;

            }
         }
         
         cout<<max_sum<<endl;


   }
   return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf (1LL<<60)
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
 
int main() {
   init_code();
   int t;
   cin >> t;
   while(t--){
         int n;
         cin>>n;

         int arr[n];
         for(int i=0;i<n;i++){
            cin>>arr[i];
         }
         
         int j=n;
         int max_sum=0;
         for(int i=0;i<n;i++){
            max_sum+=arr[i];
         }
         if(n>1){
               while(j>0){
               
               
               int k=0;
               for(int i=1;i<j;i++){
                  arr[k++]=arr[i]-arr[i-1];
               }
               j--;
               
               int sum=0;
               for(int i=0;i<j;i++){
                  sum+=arr[i];
               }
               max_sum=max(max_sum,abs(sum));

            }
         }
         
         cout<<max_sum<<endl;


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

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf (1LL<<60)
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
 
int main() {
   init_code();
   int t;
   cin >> t;
   while(t--){
         int n;
         cin>>n;

         int arr[n];
         for(int i=0;i<n;i++){
            cin>>arr[i];
         }
         
         int j=n;
         int max_sum=0;
         for(int i=0;i<n;i++){
            max_sum+=arr[i];
         }
         if(n>1){
               while(j>0){
               
               
               int k=0;
               for(int i=1;i<j;i++){
                  arr[k++]=arr[i]-arr[i-1];
               }
               j--;
               
               int sum=0;
               for(int i=0;i<j;i++){
                  sum+=arr[i];
               }
               max_sum=max(max_sum,abs(sum));

            }
         }
         
         cout<<max_sum<<endl;


   }
   return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf (1LL<<60)
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
 
int main() {
   init_code();
   int t;
   cin >> t;
   while(t--){
         int n;
         cin>>n;

         ll arr[n];
         for(int i=0;i<n;i++){
            cin>>arr[i];
         }
         
         ll j=n;
         ll max_sum=0;
         for(int i=0;i<n;i++){
            max_sum+=arr[i];
         }
         if(n>1){
               while(j>0){
               
               
               ll k=0;
               for(ll i=1;i<j;i++){
                  arr[k++]=arr[i]-arr[i-1];
               }
               j--;

               ll sum=0;
               for(int i=0;i<j;i++){
                  sum+=arr[i];
               }
               max_sum=max(max_sum,abs(sum));

            }
         }
         
         cout<<max_sum<<endl;


   }
   return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

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

using namespace std;

int main(){

    int t;
    cin>>t;

    while(t--){

        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++) cin>>arr[i];
        long long ans = accumulate(arr.begin(),arr.end(),0);
        while(n > 1){
            vector<int> temp;
             for(int i=1;i<n;i++){
               temp.push_back(arr[i] - arr[i-1]);
           }
            long long sum = accumulate(temp.begin(),temp.end(),0);
           ans = max(ans,abs(sum));
           for(int i=0;i<temp.size();i++){
               arr[i] = temp[i];
           }
           n--;
        }
        cout<<ans<<endl;
    }
}

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

using namespace std;

int main(){

    long long t;
    cin>>t;

    while(t--){

        long long n;
        cin>>n;
        vector<long long> arr(n);
        for(int i=0;i<n;i++) cin>>arr[i];
        long long ans = accumulate(arr.begin(),arr.end(),0);
        while(n > 1){
            vector<long long> temp;
             for(int i=1;i<n;i++){
               temp.push_back(arr[i] - arr[i-1]);
           }
            long long sum = accumulate(temp.begin(),temp.end(),0);
           ans = max(ans,abs(sum));
           for(int i=0;i<temp.size();i++){
               arr[i] = temp[i];
           }
           n--;
        }
        cout<<ans<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


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

using namespace std;

int main(){

    int t;
    cin>>t;

    while(t--){

        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++) cin>>arr[i];
        long long ans = accumulate(arr.begin(),arr.end(),0);
        while(n > 1){
            vector<int> temp;
             for(int i=1;i<n;i++){
               temp.push_back(arr[i] - arr[i-1]);
           }
            long long sum = accumulate(temp.begin(),temp.end(),0);
           ans = max(ans,abs(sum));
           for(int i=0;i<temp.size();i++){
               arr[i] = temp[i];
           }
           n--;
        }
        cout<<ans<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

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

using namespace std;

int main(){

    long long t;
    cin>>t;

    while(t--){

        long long n;
        cin>>n;
        vector<long long> arr(n);
        for(int i=0;i<n;i++) cin>>arr[i];
        long long ans = accumulate(arr.begin(),arr.end(),0);
        while(n > 1){
            vector<long long> temp;
             for(int i=1;i<n;i++){
               temp.push_back(arr[i] - arr[i-1]);
           }
            long long sum = accumulate(temp.begin(),temp.end(),0);
           ans = max(ans,abs(sum));
           for(int i=0;i<temp.size();i++){
               arr[i] = temp[i];
           }
           n--;
        }
        cout<<ans<<endl;
    }
}

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

using namespace std;

int main(){

    long long t;
    cin>>t;

    while(t--){

        long long n;
        cin>>n;
        vector<long long> arr(n);
        for(int i=0;i<n;i++) cin>>arr[i];
        long long ans = accumulate(arr.begin(),arr.end(),0LL);
        while(n > 1){
            vector<long long> temp;
             for(int i=1;i<n;i++){
               temp.push_back(arr[i] - arr[i-1]);
           }
            long long sum = accumulate(temp.begin(),temp.end(),0LL);
           ans = max(ans,abs(sum));
           for(int i=0;i<temp.size();i++){
               arr[i] = temp[i];
           }
           n--;
        }
        cout<<ans<<endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: Kotlin 1.9

Previous submission (verdict: Time limit exceeded on test 9):
fun main() {
    repeat(readln().toInt()) {
        val (n, k) = readln().split(" ").map(String::toInt)
        val list = readln().split(" ").map(String::toInt)

        val histo = hashMapOf<Int, Int>()
        for (i in list) {
            histo[i] = histo.getOrDefault(i, 0) + 1
        }

        val max = histo.maxBy { it.value }.key

        var kp = k
        while (kp != 0 && histo.size > 1) {
            val min = histo.minBy { it.value + if(it.key == max) 1_000_000_000 else 0 }
            if (kp >= min.value) {
                histo.remove(min.key)
                histo[max] = histo[max]!! + min.value
                kp -= min.value
            } else {
                histo[min.key] = histo[min.key]!! - kp
                kp = 0
            }
        }

        println(histo.size)
    }
}

Submission (verdict: Accepted):
fun main() {
    repeat(readln().toInt()) {
        val (n, k) = readln().split(" ").map(String::toInt)
        val list = readln().split(" ").map(String::toInt)

        val histo = hashMapOf<Int, Int>()
        for (i in list) {
            histo[i] = histo.getOrDefault(i, 0) + 1
        }

        val pairs = histo.toList().sortedBy { it.second }

        var ptr = 0

        var kp = k
        while (kp != 0 && histo.size > 1) {
            if (ptr == pairs.size - 1) break
            val min = pairs[ptr]
            if (kp >= min.second) {
                ptr += 1
                kp -= min.second
            } else {
                kp = 0
            }
        }

        println(pairs.size - ptr)
    }
}