ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 16):
#include "bits/stdc++.h"

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define yes return void(cout << "YES\n");
#define no return void(cout << "NO\n");
#define YN(X) cout << ( X ? "Yes" : "No" ) << endl;
#define fr(n) for(int i = 0 ; i < n ; i++)
#define frj(n) for(int j = 0 ; j < n ; j++)
#define fra(u, v) for(auto u : v)
#define fr1(n) for(int i = 1 ; i <= n ; i++)
#define frj1(n) for(int j = 1 ; j <= n ; j++)
#define ret(ans) return void(cout << ans << endl);
#define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define looz cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
#define int long long
#define ll long long
#define ld long double
#define endl '\n'

const int MAX = 1e3 + 7;

string a, b, c;
int dp[MAX][MAX], n, m;

int calc(int i, int j, int k){
    if (i == c.size()) return 0;
    int &ret = dp[i][j];
    if (~ret) return ret;
    ret = 1e10;
    if (j < n && c[i] == a[j]){
        ret = min(ret, calc(i + 1, j + 1, k));
    }
    if (k < m && c[i] == b[k]){
        ret = min(ret, calc(i + 1, j, k + 1));
    }
    if (j < n && c[i] != a[j]){
        ret = min(ret, calc(i + 1, j + 1, k) + 1);
    }
    if (k < m && c[i] != b[k]){
        ret = min(ret, calc(i + 1, j, k + 1) + 1);
    }
    return ret;
}

void solve() {
    cin >> a >> b >> c;
    n = a.size(), m = b.size();
    fr(c.size() + 3)frj(c.size() + 3) dp[i][j] = -1;
    cout << calc(0, 0, 0) << endl;
}

signed main() {
    looz
//    files
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int t;

    cin >> t;

    for(int i = 0; i < t; i++)
    {
        int n, k, tmp;

        cin >> n >> k;

        std::unordered_map<int, int> m;
        for(int j = 0; j < n; j++)
        {
            cin >> tmp;
            m[tmp]++;
        }

        std::vector<int> v;

        for(auto it: m)
        {
            v.emplace_back(it.second);
        }

        std::sort(v.begin(), v.end());

        int j = 0;
        for(; j < v.size(); j++)
        {
            k -= v[j];
            if (k <= 0)
                break;
        }

        if(j >= v.size() - 1)
            cout << 1 << endl;
        else
            cout << v.size() - j - 1 + (k < 0?1:0) << endl;
    }
}


Submission (verdict: Time limit exceeded on test 13):
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int t;

    cin >> t;

    for(int i = 0; i < t; i++)
    {
        int n, k, tmp;

        cin >> n >> k;

	    if(n <= k + 1)
        {
            cout << 1 << endl;
			for(int j = 0; j < n; j++)
				cin >> tmp;
            continue;
        }

        std::unordered_map<int, int> m;
        for(int j = 0; j < n; j++)
        {
            cin >> tmp;
            m[tmp]++;
        }

        std::vector<int> v;

        for(auto it: m)
        {
            v.emplace_back(it.second);
        }

        std::sort(v.begin(), v.end());

        int j = 0;
        for(; j < v.size(); j++)
        {
            k -= v[j];
            if (k <= 0)
                break;
        }

        if(j >= v.size() - 1)
            cout << 1 << endl;
        else
            cout << v.size() - j - 1 + (k < 0?1:0) << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 11):
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int t;

    cin >> t;

    for(int i = 0; i < t; i++)
    {
        int n, k, tmp;

        cin >> n >> k;

        std::unordered_map<int, int> m;
        for(int j = 0; j < n; j++)
        {
            cin >> tmp;
            m[tmp]++;
        }

        std::vector<int> v;

        for(auto it: m)
        {
            v.emplace_back(it.second);
        }

        std::sort(v.begin(), v.end());

        int j = 0;
        for(; j < v.size(); j++)
        {
            k -= v[j];
            if (k <= 0)
                break;
        }

        if(j >= v.size() - 1)
            cout << 1 << endl;
        else
            cout << v.size() - j - 1 + (k < 0?1:0) << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 13):
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int t;

    cin >> t;

    for(int i = 0; i < t; i++)
    {
        int n, k, tmp;

        cin >> n >> k;

	    if(n <= k + 1)
        {
            cout << 1 << endl;
			for(int j = 0; j < n; j++)
				cin >> tmp;
            continue;
        }

        std::unordered_map<int, int> m;
        for(int j = 0; j < n; j++)
        {
            cin >> tmp;
            m[tmp]++;
        }

        std::vector<int> v;

        for(auto it: m)
        {
            v.emplace_back(it.second);
        }

        std::sort(v.begin(), v.end());

        int j = 0;
        for(; j < v.size(); j++)
        {
            k -= v[j];
            if (k <= 0)
                break;
        }

        if(j >= v.size() - 1)
            cout << 1 << endl;
        else
            cout << v.size() - j - 1 + (k < 0?1:0) << endl;
    }
}


Submission (verdict: Accepted):
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int t;

    cin >> t;

    for(int i = 0; i < t; i++)
    {
        int n, k, tmp;

        cin >> n >> k;

	    if(n <= k + 1)
        {
            cout << 1 << endl;
			for(int j = 0; j < n; j++)
				cin >> tmp;
            continue;
        }

        std::vector<int> v(n);
        for(int j = 0; j < n; j++)
            cin >> v[j];

        std::sort(v.begin(), v.end());

		std::vector<int> cnt{1};
		for(int j = 1; j < n; j++)
		{
			if(v[j] == v[j - 1])
				cnt.back()++;
			else
				cnt.push_back(1);
		}
		std::sort(cnt.begin(), cnt.end());

        int j = 0;
        for(; j < cnt.size(); j++)
        {
            k -= cnt[j];
            if (k <= 0)
                break;
        }

        if(j >= cnt.size() - 1)
            cout << 1 << endl;
        else
            cout << cnt.size() - j - 1 + (k < 0?1:0) << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 19):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define f(k,a,b) for(int k = a;k<b;k++)
#define ok(i) cout<<i<<endl
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}
ll mod_add(ll a, ll b, ll m = MOD) {
    return ((a % m + b % m) % m + m) % m;
}
ll mod_sub(ll a, ll b, ll m = MOD) {
    return ((a % m - b % m) % m + m) % m;
}
ll mod_mul(ll a, ll b, ll m = MOD) {
    return ((a % m) * (b % m)) % m;
}

int main() {
    fast_io();

    int testcases;
    cin >> testcases;
    while (testcases--) {
        unordered_map<int,int>m;
        int n,k;
        cin>>n>>k;
        vi v(n);
        for(int i =0;i<n;i++){
            cin>>v[i];
            m[v[i]]++;
        }
        if((n==1) || (n == k)){cout<<1<<endl;}
        else{
            vi check;
            unordered_map<int,int>::iterator it = m.begin();
            for (it; it != m.end(); ++it) {
                check.push_back(it->second);
            }
            sort(check.begin(),check.end());
            for(int i =0;i<check.size();i++){
                if(check[i]<=k){k-=check[i];}
                else{
                    cout<<check.size()-i<<endl;
                    break;
                }
            }
        }
    }

    return 0;
}
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;
#define ll long long
#define vi vector<int>
const ll MOD = 1e9 + 7;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();

    int testcases;
    cin >> testcases;
    while (testcases--) {
        unordered_map<int, int> freq;
        int n, k;
        cin >> n >> k;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            freq[x]++;
        }

        if (n == 1 || n == k) {
            cout << 1 << endl;
            continue;
        }

        // Collect frequencies and sort them
        vector<int> frequencies;
        for (const auto &entry : freq) {
            frequencies.push_back(entry.second);
        }
        sort(frequencies.begin(), frequencies.end());

        // Remove elements greedily
        int remaining_elements = frequencies.size();
        for (int count : frequencies) {
            if (k >= count) {
                k -= count;
                remaining_elements--;
            } else {
                break;
            }
        }
        cout << remaining_elements << endl;
    }

    return 0;
}


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

int main() {
    ll t;
    cin >> t;
    while (t--) {
        ll n, k, c = 0, res = 0;
        cin >> n >> k;
        vector<ll> a(n);
        map<ll, ll> mp;

        for (ll i = 0; i < n; i++) {
            cin >> a[i];
            if (mp[a[i]] == 0) c++;
            mp[a[i]]++;
        }

        vector<ll> v;
        for (auto i : mp) {
            v.push_back(i.second);
        }

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

        for (ll i = 0; i < v.size(); i++) {
            k -= v[i];
            if (k >= 0)
                res++;
            else
                break;
        }

        //cout << "c=" << c << " res=" << res << endl;
        if(c-res==0)cout<<"1"<<endl;
        else cout << c - res << endl;
    }
    return 0;
}
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;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define f(k,a,b) for(int k = a;k<b;k++)
#define ok(i) cout<<i<<endl
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}
ll mod_add(ll a, ll b, ll m = MOD) {
    return ((a % m + b % m) % m + m) % m;
}
ll mod_sub(ll a, ll b, ll m = MOD) {
    return ((a % m - b % m) % m + m) % m;
}
ll mod_mul(ll a, ll b, ll m = MOD) {
    return ((a % m) * (b % m)) % m;
}

int main() {
    fast_io();

    int testcases;
    cin >> testcases;
    while (testcases--) {
        unordered_map<int,int>m;
        int n,k;
        cin>>n>>k;
        vi v(n);
        for(int i =0;i<n;i++){
            cin>>v[i];
            m[v[i]]++;
        }
        if((n==1) || (n == k)){cout<<1<<endl;}
        else{
            vi check;
            priority_queue<int, vector<int>, greater<int>>min_h;
            for(unordered_map<int,int>::iterator it = m.begin();it!=m.end();it++){
                min_h.push(it->second);
            }
            while(min_h.size()!=0 && k>=min_h.top()){
                k-=min_h.top();
                min_h.pop();
            }
            cout<<min_h.size()<<endl;
        }
    }

    return 0;
}

Submission (verdict: Time limit exceeded on test 14):

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
const ll MOD = 1e9 + 7;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();

    int testcases;
    cin >> testcases;
    while (testcases--) {
        unordered_map<int, int> freq;
        int n, k;
        cin >> n >> k;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            freq[x]++;
        }

        if (n == 1 || n == k) {
            cout << 1 << endl;
            continue;
        }

        // Collect frequencies and sort them
        vector<int> frequencies;
        for (const auto &entry : freq) {
            frequencies.push_back(entry.second);
        }
        sort(frequencies.begin(), frequencies.end());

        // Remove elements greedily
        int remaining_elements = frequencies.size();
        for (int count : frequencies) {
            if (k >= count) {
                k -= count;
                remaining_elements--;
            } else {
                break;
            }
        }
        cout << remaining_elements << endl;
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 19):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define f(k,a,b) for(int k = a;k<b;k++)
#define ok(i) cout<<i<<endl
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}
ll mod_add(ll a, ll b, ll m = MOD) {
    return ((a % m + b % m) % m + m) % m;
}
ll mod_sub(ll a, ll b, ll m = MOD) {
    return ((a % m - b % m) % m + m) % m;
}
ll mod_mul(ll a, ll b, ll m = MOD) {
    return ((a % m) * (b % m)) % m;
}

int main() {
    fast_io();

    int testcases;
    cin >> testcases;
    while (testcases--) {
        unordered_map<int,int>m;
        int n,k;
        cin>>n>>k;
        vi v(n);
        for(int i =0;i<n;i++){
            cin>>v[i];
            m[v[i]]++;
        }
        if((n==1) || (n == k)){cout<<1<<endl;}
        else{
            vi check;
            unordered_map<int,int>::iterator it = m.begin();
            for (it; it != m.end(); ++it) {
                check.push_back(it->second);
            }
            sort(check.begin(),check.end());
            for(int i =0;i<check.size();i++){
                if(check[i]<=k){k-=check[i];}
                else{
                    cout<<check.size()-i<<endl;
                    break;
                }
            }
        }
    }

    return 0;
}

Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define f(k,a,b) for(int k = a;k<b;k++)
#define ok(i) cout<<i<<endl
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}
ll mod_add(ll a, ll b, ll m = MOD) {
    return ((a % m + b % m) % m + m) % m;
}
ll mod_sub(ll a, ll b, ll m = MOD) {
    return ((a % m - b % m) % m + m) % m;
}
ll mod_mul(ll a, ll b, ll m = MOD) {
    return ((a % m) * (b % m)) % m;
}

int main() {
    fast_io();

    int testcases;
    cin >> testcases;
    while (testcases--) {
        unordered_map<int,int>m;
        int n,k;
        cin>>n>>k;
        vi v(n);
        for(int i =0;i<n;i++){
            cin>>v[i];
            m[v[i]]++;
        }
        if((n==1) || (n == k)){cout<<1<<endl;}
        else{
            vi check;
            priority_queue<int, vector<int>, greater<int>>min_h;
            for(unordered_map<int,int>::iterator it = m.begin();it!=m.end();it++){
                min_h.push(it->second);
            }
            while(k>=min_h.top()){
                k-=min_h.top();
                min_h.pop();
            }
            cout<<min_h.size()<<endl;
        }
    }

    return 0;
}
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;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define f(k,a,b) for(int k = a;k<b;k++)
#define ok(i) cout<<i<<endl
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}
ll mod_add(ll a, ll b, ll m = MOD) {
    return ((a % m + b % m) % m + m) % m;
}
ll mod_sub(ll a, ll b, ll m = MOD) {
    return ((a % m - b % m) % m + m) % m;
}
ll mod_mul(ll a, ll b, ll m = MOD) {
    return ((a % m) * (b % m)) % m;
}

int main() {
    fast_io();

    int testcases;
    cin >> testcases;
    while (testcases--) {
        unordered_map<int,int>m;
        int n,k;
        cin>>n>>k;
        vi v(n);
        for(int i =0;i<n;i++){
            cin>>v[i];
            m[v[i]]++;
        }
        if((n==1) || (n == k)){cout<<1<<endl;}
        else{
            vi check;
            priority_queue<int, vector<int>, greater<int>>min_h;
            for(unordered_map<int,int>::iterator it = m.begin();it!=m.end();it++){
                min_h.push(it->second);
            }
            while(k>=min_h.top()){
                k-=min_h.top();
                min_h.pop();
            }
            cout<<min_h.size()<<endl;
        }
    }

    return 0;
}

Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define f(k,a,b) for(int k = a;k<b;k++)
#define ok(i) cout<<i<<endl
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}
ll mod_add(ll a, ll b, ll m = MOD) {
    return ((a % m + b % m) % m + m) % m;
}
ll mod_sub(ll a, ll b, ll m = MOD) {
    return ((a % m - b % m) % m + m) % m;
}
ll mod_mul(ll a, ll b, ll m = MOD) {
    return ((a % m) * (b % m)) % m;
}

int main() {
    fast_io();

    int testcases;
    cin >> testcases;
    while (testcases--) {
        unordered_map<int,int>m;
        int n,k;
        cin>>n>>k;
        vi v(n);
        for(int i =0;i<n;i++){
            cin>>v[i];
            m[v[i]]++;
        }
        if((n==1) || (n == k)){cout<<1<<endl;}
        else{
            vi check;
            priority_queue<int, vector<int>, greater<int>>min_h;
            for(unordered_map<int,int>::iterator it = m.begin();it!=m.end();it++){
                min_h.push(it->second);
            }
            while(min_h.size()!=0 && k>=min_h.top()){
                k-=min_h.top();
                min_h.pop();
            }
            cout<<min_h.size()<<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;



// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



using ll = long long;

using ull = unsigned long long;



#define pb(v) push_back(v)

#define all(v) (v).begin(), (v).end()

#define rall(v) (v).rbegin(), (v).rend()

#define MSET(c, v) memset(c, v, sizeof(c))

#define debug(x) cout << #x << " is " << x << endl



const int NEGINF = 0xC0C0C0C0;

const int NULO = -1;

const double EPS = 1e-10;

const ll mod = 1e9 + 7;

const ll llInf = 4e17;

const int inf = 2e9;



int dy[] = {0,1,-1,0};

int dx[] = {1,0,0,-1};



template <typename T,typename U>

std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {

return {l.first+r.first,l.second+r.second};

}



const int maxn = 2e5 + 100;



ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }



ll a[maxn];

void solveTestCase(int test) {



int n;

cin >> n;

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

cin >> a[i];

}

for(int i = 1; i <= n - 2; i++) {

if(a[i] > a[i + 1]) {

cout << "NO" << endl;

return;

} else {

a[i + 1] -= a[i];

a[i] = 0;

}

}

cout << "YES" << endl;

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

//     cout << a[i] << " ";

// }

// cout << endl;

}



int main() {

ios::sync_with_stdio(false);

int test = 1;

cin >> test;

for (int t = 1; t <= test; t++) {

solveTestCase(t);

}



return 0;

}

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

using namespace std;



// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



using ll = long long;

using ull = unsigned long long;



#define pb(v) push_back(v)

#define all(v) (v).begin(), (v).end()

#define rall(v) (v).rbegin(), (v).rend()

#define MSET(c, v) memset(c, v, sizeof(c))

#define debug(x) cout << #x << " is " << x << endl



const int NEGINF = 0xC0C0C0C0;

const int NULO = -1;

const double EPS = 1e-10;

const ll mod = 1e9 + 7;

const ll llInf = 4e17;

const int inf = 2e9;



int dy[] = {0,1,-1,0};

int dx[] = {1,0,0,-1};



template <typename T,typename U>

std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {

return {l.first+r.first,l.second+r.second};

}



const int maxn = 2e5 + 100;



ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }



ll a[maxn];

void solveTestCase(int test) {



int n;

cin >> n;

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

cin >> a[i];

}

bool ok = true;

for(int i = 1; i <= n - 2; i++) {

if(a[i] > a[i + 1]) {

ok = false;

break;

} else {

a[i + 1] -= a[i];

a[i] = 0;

}

}

cout << (ok ? "YES" : "NO") << endl;

}



int main() {

ios::sync_with_stdio(false);

int test = 1;

cin >> test;

for (int t = 1; t <= test; t++) {

solveTestCase(t);

}



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;



// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



using ll = long long;

using ull = unsigned long long;



#define pb(v) push_back(v)

#define all(v) (v).begin(), (v).end()

#define rall(v) (v).rbegin(), (v).rend()

#define MSET(c, v) memset(c, v, sizeof(c))

#define debug(x) cout << #x << " is " << x << endl



const int NEGINF = 0xC0C0C0C0;

const int NULO = -1;

const double EPS = 1e-10;

const ll mod = 1e9 + 7;

const ll llInf = 4e17;

const int inf = 2e9;



int dy[] = {0,1,-1,0};

int dx[] = {1,0,0,-1};



template <typename T,typename U>

std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {

return {l.first+r.first,l.second+r.second};

}



const int maxn = 2e5 + 100;



ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }



int a[maxn];

void solveTestCase(int test) {



int n;

cin >> n;

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

cin >> a[i];

}

int last = a[n];

for(int i = 1; i <= n - 2; i++) {

if(a[i] > last) {

if(a[i] > a[i + 1]) {

cout << "NO" << endl;

return;

} else {

a[i + 1] -= a[i];

a[i] = 0;

//cout << a[i] << " " << a[i + 1] << endl;

}

}

}

cout << "YES" << endl;

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

//     cout << a[i] << " ";

// }

// cout << endl;

}



int main() {

ios::sync_with_stdio(false);

int test = 1;

cin >> test;

for (int t = 1; t <= test; t++) {

solveTestCase(t);

}



return 0;

}