ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        string s; cin >> s;
        int twos = 0, threes = 0, sum = 0;
        for(char n : s){
            int curr = n - '0';
            sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; }
        }
        bool works = false;
        int need = 9 - (sum % 9);
        if(need % 2 == 1){ need+=9; }
        if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? (need%6 == 0 ? 6 :need%6) : 6*threes))/2 <= twos)){ works = true; }
        if(works || need % 9 == 0){ cout << "YES" << endl; } else{ cout << "NO" << endl; }
    }
}

Submission (verdict: Accepted):
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        string s; cin >> s;
        int twos = 0, threes = 0, sum = 0;
        for(char n : s){
            int curr = n - '0';
            sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; }
        }
        bool works = false;
        int need = 9 - (sum % 9);
        if(need % 2 == 1){ need+=9; }
        if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? need - (need % 6) : 6*threes))/2 <= twos)){ works = true; }
        if(works || need % 9 == 0){ cout << "YES" << endl; } else{ cout << "NO" << endl; }
    }
}
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;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        unordered_map<int, int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; }
        vector<int> freq (n+1);
        int hi = 0, lo = INT32_MAX;
        for(auto& [key, val] : nums){ freq[val]++; hi = max(val, hi); lo = min(lo, val); }
        int remove = 0;
        for(int i = lo; i < hi+1; i++){
            if(freq[i] == 0){ continue; }
            if(freq[i]*i <= m){ remove += freq[i]; m -= freq[i]*i; continue; }
            remove += m/i;
            break;
        }
        cout << (nums.size() - remove == 0 ? 1 : nums.size() - remove) << '\n';
    }
}

Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;

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

    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        unordered_map<int, int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; }
        vector<int> freq;
        for(auto& [key, val] : nums){ freq.push_back(val); }
        sort(freq.begin(), freq.end());
        int i = 0;
        while(i < freq.size()-1){
            if(m < freq[i]){ break; }
            m -= freq[i]; i++;
        }
        cout << freq.size() - i << '\n';
    }
}
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;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        unordered_map<int, int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; }
        vector<int> freq;
        for(auto& [key, val] : nums){ freq.push_back(val); }
        sort(freq.begin(), freq.end());
        int i = 0;
        while(i < freq.size()-1){
            if(m < freq[i]){ break; }
            m -= freq[i]; i++;
        }
        cout << freq.size() - i << '\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;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        unordered_map<int, int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; }
        vector<int> freq;
        for(auto& [key, val] : nums){ freq.push_back(val); }
        sort(freq.begin(), freq.end());
        int i = 0;
        while(i < freq.size()-1){
            if(m < freq[i]){ break; }
            m -= freq[i]; i++;
        }
        cout << freq.size() - i << '\n';
    }
}

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

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        unordered_map<int, int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; }
        vector<int> freq;
        int i = 0, removed = 0, greatest = 0;
        for(auto& [key, val] : nums){ freq.push_back(val); greatest = max(greatest, val); }
        bool runThrough = false;
        while(i < freq.size()){
            if(m < freq[i]){ i++; continue; }
            if(freq[i] == greatest){ if(!runThrough){ runThrough = true; i++; continue; } }
            m -= freq[i]; removed++; i++;
        }
        cout << freq.size() - removed << '\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;

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

    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        unordered_map<int, int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; }
        vector<int> freq;
        for(auto& [key, val] : nums){ freq.push_back(val); }
        sort(freq.begin(), freq.end());
        int i = 0;
        while(i < freq.size()-1){
            if(m < freq[i]){ break; }
            m -= freq[i]; i++;
        }
        cout << freq.size() - i << '\n';
    }
}

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

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

    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        vector<int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums.push_back(x); }
        vector<int> freq;
        sort(nums.begin(), nums.end());
        int last = -1, f = 0;
        for(int n : nums){ 
            if(last == -1){ last = n; f++; }
            else if(last == n){ f++; }
            else{ last = n; freq.push_back(f); f = 1;}
        }
        freq.push_back(f);
        sort(freq.begin(), freq.end());
        int i = 0;
        while(i < freq.size()-1){
            if(m < freq[i]){ break; }
            m -= freq[i]; i++;
        }
        cout << freq.size() - i << '\n';
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        unordered_map<int, int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; }
        vector<int> freq;
        int i = 0, removed = 0, greatest = 0;
        for(auto& [key, val] : nums){ freq.push_back(val); greatest = max(greatest, val); }
        bool runThrough = false;
        while(i < freq.size()){
            if(m < freq[i]){ i++; continue; }
            if(freq[i] == greatest){ if(!runThrough){ runThrough = true; i++; continue; } }
            m -= freq[i]; removed++; i++;
        }
        cout << freq.size() - removed << '\n';
    }
}

Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        unordered_map<int, int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; }
        vector<int> freq (n+1);
        int hi = 0, lo = INT32_MAX;
        for(auto& [key, val] : nums){ freq[val]++; hi = max(val, hi); lo = min(lo, val); }
        int remove = 0;
        for(int i = lo; i < hi+1; i++){
            if(freq[i] == 0){ continue; }
            if(freq[i]*i <= m){ remove += freq[i]; m -= freq[i]*i; continue; }
            remove += m/i;
            break;
        }
        cout << (nums.size() - remove == 0 ? 1 : nums.size() - remove) << '\n';
    }
}
Problem: 2050B - Transfusion
Language: Java 21


Submission (verdict: Wrong answer on test 3):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;

        int t = Integer.parseInt(reader.readLine());

        while((line = reader.readLine()) != null) {
            inputs.add(line);
        }

        String[] result = new String[t];

        int j = 0;

        for(int i = 0; i < t; i++){
            int n = Integer.parseInt(inputs.get(j));
            String[] strings = inputs.get(j+1).split(" ");
            j += 2;

            int[] data = new int[n];

            for(int k = 0; k < n; k++){
                data[k] = Integer.parseInt(strings[k]);
            }

            result[i] = solution(data);
        }

        for(String r: result){
            System.out.println(r);
        }
    }

    public static String solution(int[] nums){
        int oddT = 0;
        int o = 0;

        int evenT = 0;
        int e = 0;

        for(int i = 0; i < nums.length; i++){
            if(i%2 == 0){
                evenT += nums[i];
                e += 1;
            }
            else{
                oddT += nums[i];
                o += 1;
            }
        }




        if((oddT+evenT) % nums.length != 0){
            return "NO";
        }



        int target = (oddT+evenT)/nums.length;
        boolean ans = oddT/o == target && evenT/e == target;


        if(ans){
            return "YES";
        }
        return "NO";


    }


}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout<<"\n";
const int mod = 1e9+7;
const int N = 1e5+10;
// <-------------HereWeGo------------->
void solve(){
	int l,r;
	cin>>l>>r;
	if(r-l == 2){
		cout<<l<<" "<<l+1<<" "<<r<<" ";
		nxt
	}
	else{
		int a = (1<<int(log2(r)));

		if(a<=l){
			int l1=0,l2=0,i=0;
			while(r&(1<<int(log2(r) - i))){

				l1= l1| (1<<int(log2(r) - i));
				i++;
			}
			i=0;
			while(l&(1<<int(log2(l) - i))){
				l2 = l2 | (1<<int(log2(l)-i));
				i++;
			}
            
			l1=min(l1,l2);
			int b1= l1^r,b2=l1^l;
			a= (1<<int(log2(b1)));

			cout<< (l1^a)-1<<" "<<(l1^a)<<" "<<r;nxt
		}
		else {
			cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
		}
		
	}
	
}
int main(){
    life saver
    int t;cin>>t;
	while(t--) solve();
	 return 0;
}


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout<<"\n";
const int mod = 1e9+7;
const int N = 1e5+10;
// <-------------HereWeGo------------->
void solve(){
	int l,r;
	cin>>l>>r;
	if(r-l == 2){
		cout<<l<<" "<<l+1<<" "<<r<<" ";
		nxt
	}
	else{
		int a = (1<<int(log2(r)));

		if(a<=l){
			int l1=0,l2=0,i=0;
			while(r&(1<<int(log2(r) - i))){

				l1= l1| (1<<int(log2(r) - i));
				i++;
			}
			i=0;
			while(l&(1<<int(log2(l) - i))){
				l2 = l2 | (1<<int(log2(l)-i));
				i++;
			}
            
			l1=min(l1,l2);
			int b1= l1^r,b2=l1^l;
			a= (1<<int(log2(b1)));

			cout<< (l1^a)-1<<" "<<(l1^a)<<" "<<r;nxt
		}
		else if(a-l==1){
			cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
		}
		else{
			cout<<l<<" "<<a-1<<" "<<a<<" ";nxt
		}
		
	}
	
}
int main(){
    life saver
    int t;cin>>t;
	while(t--) solve();
	 return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout<<"\n";
const int mod = 1e9+7;
const int N = 1e5+10;
// <-------------HereWeGo------------->
void solve(){
	int l,r;
	cin>>l>>r;
	if(r-l == 2){
		cout<<l<<" "<<l+1<<" "<<r<<" ";
		nxt
	}
	else{
		int a = (1<<int(log2(r)));

		if(a<=l){
			int l1=0,l2=0,i=0;
			while(r&(1<<int(log2(r) - i))){

				l1= l1| (1<<int(log2(r) - i));
				i++;
			}
			i=0;
			while(l&(1<<int(log2(l) - i))){
				l2 = l2 | (1<<int(log2(l)-i));
				i++;
			}
            
			l1=min(l1,l2);
			int b1= l1^r,b2=l1^l;
			a= (1<<int(log2(b1)));

			cout<< (l1^a)-1<<" "<<(l1^a)<<" "<<r;nxt
		}
		else if(a-l==1){
			cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
		}
		else{
			cout<<l<<" "<<a-1<<" "<<a<<" ";nxt
		}
		
	}
	
}
int main(){
    life saver
    int t;cin>>t;
	while(t--) solve();
	 return 0;
}


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout<<"\n";
const int mod = 1e9+7;
const int N = 1e5+10;
// <-------------HereWeGo------------->
void solve(){
	int l,r;
	cin>>l>>r;
	if(r-l == 2){
		cout<<l<<" "<<l+1<<" "<<r<<" ";
		nxt
	}
	else{
		int a = (1<<int(log2(r)));

		if(a<=l){
			int l1=0,l2=0,i=0;
			while(r&(1<<int(log2(r) - i))){

				l1= l1| (1<<int(log2(r) - i));
				i++;
			}
			i=0;
			while(l&(1<<int(log2(l) - i))){
				l2 = l2 | (1<<int(log2(l)-i));
				i++;
			}
            
			l1=min(l1,l2);
			int b1= l1^r,b2=l1^l;
			a= (1<<int(log2(b1)));
			a=l1^a;
			if(a-l==1){
				cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
			}
			else{
				cout<<l<<" "<<a-1<<" "<<a<<" ";nxt
			}
		}
		else if(a-l==1){
			cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
		}
		else{
			cout<<l<<" "<<a-1<<" "<<a<<" ";nxt
		}
		
	}
	
}
int main(){
    life saver
    int t;cin>>t;
	while(t--) solve();
	 return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout<<"\n";
const int mod = 1e9+7;
const int N = 1e5+10;
// <-------------HereWeGo------------->
void solve(){
	int l,r;
	cin>>l>>r;
	if(r-l == 2){
		cout<<l<<" "<<l+1<<" "<<r<<" ";
		nxt
	}
	else{
		int a = (1<<int(log2(r)));

		if(a<=l){
			int l1=0,l2=0,i=0;
			while(r&(1<<int(log2(r) - i))){

				l1= l1| (1<<int(log2(r) - i));
				i++;
			}
			i=0;
			while(l&(1<<int(log2(l) - i))){
				l2 = l2 | (1<<int(log2(l)-i));
				i++;
			}
            
			l1=min(l1,l2);
			int b1= l1^r,b2=l1^l;
			a= (1<<int(log2(b1)));

			cout<< (l1^a)-1<<" "<<(l1^a)<<" "<<r;nxt
		}
		else {
			cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
		}
		
	}
	
}
int main(){
    life saver
    int t;cin>>t;
	while(t--) solve();
	 return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout<<"\n";
const int mod = 1e9+7;
const int N = 1e5+10;
// <-------------HereWeGo------------->
void solve(){
	int l,r;
	cin>>l>>r;
	if(r-l == 2){
		cout<<l<<" "<<l+1<<" "<<r<<" ";
		nxt
	}
	else{
		int a = (1<<int(log2(r)));

		if(a<=l){
			int l1=0,l2=0,i=0;
			while(r&(1<<int(log2(r) - i))){

				l1= l1| (1<<int(log2(r) - i));
				i++;
			}
			i=0;
			while(l&(1<<int(log2(l) - i))){
				l2 = l2 | (1<<int(log2(l)-i));
				i++;
			}
            
			l1=min(l1,l2);
			int b1= l1^r,b2=l1^l;
			a= (1<<int(log2(b1)));
			a=l1^a;
			if(a-l==1){
				cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
			}
			else{
				cout<<l<<" "<<a-1<<" "<<a<<" ";nxt
			}
		}
		else if(a-l==1){
			cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
		}
		else{
			cout<<l<<" "<<a-1<<" "<<a<<" ";nxt
		}
		
	}
	
}
int main(){
    life saver
    int t;cin>>t;
	while(t--) solve();
	 return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout<<"\n";
const int mod = 1e9+7;
const int N = 1e5+10;
// <-------------HereWeGo------------->
void solve(){
	int l,r;
	cin>>l>>r;
	if(r-l == 2){
		cout<<l<<" "<<l+1<<" "<<r<<" ";
		nxt
	}
	else{
		int a = (1<<int(log2(r)));

		if(a<=l){
			int l1=0,i=0;
			while((r&(1<<int(log2(r) - i))) == (l&(1<<int(log2(l) - i)))){

				l1= l1| (r&(1<<int(log2(r) - i)));
				i++;
			}
			int b1= l1^r,b2=l1^l;
			a= (1<<int(log2(b1)));
			a=l1^a;
			if(a-l==1){            
				cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
			}
			else{
				cout<<l<<" "<<a-1<<" "<<a<<" ";nxt
			}
		}
		else if(a-l==1){
			cout<<a-1<<" "<<a<<" "<<r<<" ";nxt
		}
		else{
			cout<<l<<" "<<a-1<<" "<<a<<" ";nxt
		}
		
	}
	
}
int main(){
    life saver
    int t;cin>>t;
	while(t--) solve();
	 return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

using namespace std;

int a[200009];

int main() {

int t;

cin >> t;

while (t--) {

int n;

cin >> n;

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

cin >> a[i];

}

if (a[1] > a[2]) {

cout << "NO" << endl;

} else {

bool flag = true;

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

if (a[i] < a[i - 1]) {

int t = min(a[i - 2], a[i - 1]);

a[i - 2] -= t;

a[i - 1] -= t;

if (a[i] < a[i - 1]) {

flag = false;

break;

}

}

}



if (flag) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}

}

return 0;

}



Submission (verdict: Wrong answer on test 2):
#include <iostream>

using namespace std;

int a[200009];

int main() {

int t;

cin >> t;

while (t--) {

int n;

cin >> n;

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

cin >> a[i];

}

if (a[1] > a[2]) {

cout << "NO" << endl;

} else {

bool flag = true;

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

if (a[i] < a[i - 1]) {

int t = min(a[i - 2], a[i - 1]);

a[i - 2] -= t;

a[i - 1] -= t;

if (a[i] < a[i - 1]) {

flag = false;

break;

}

}

}



if (flag) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

using namespace std;

int a[200009];

int main() {

int t;

cin >> t;

while (t--) {

int n;

cin >> n;

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

cin >> a[i];

}

if (a[1] > a[2]) {

cout << "NO" << endl;

} else {

bool flag = true;

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

if (a[i] < a[i - 1]) {

int t = min(a[i - 2], a[i - 1]);

a[i - 2] -= t;

a[i - 1] -= t;

if (a[i] < a[i - 1]) {

flag = false;

break;

}

}

}



if (flag) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}

}

return 0;

}



Submission (verdict: Wrong answer on test 2):
#include <algorithm>

#include <iostream>

using namespace std;

long long a[200009];

int main() {

long long t;

cin >> t;

while (t--) {

long long n;

cin >> n;

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

cin >> a[i];

}

if (a[1] > a[2]) {

cout << "NO" << endl;

} else {

bool flag = true;

for (long long i = 3; i <= n; i++) {

if (a[i] < a[i - 1]) {

long long t = min(a[i - 2], a[i - 1]);

a[i - 2] -= t;

a[i - 1] -= t;

if (a[i] < a[i - 1]) {

flag = false;

break;

}

}

}



if (flag) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <algorithm>

#include <iostream>

using namespace std;

long long a[200009];

int main() {

long long t;

cin >> t;

while (t--) {

long long n;

cin >> n;

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

cin >> a[i];

}

if (a[1] > a[2]) {

cout << "NO" << endl;

} else {

bool flag = true;

for (long long i = 3; i <= n; i++) {

if (a[i] < a[i - 1]) {

long long t = min(a[i - 2], a[i - 1]);

a[i - 2] -= t;

a[i - 1] -= t;

if (a[i] < a[i - 1]) {

flag = false;

break;

}

}

}



if (flag) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}

}

return 0;

}



Submission (verdict: Wrong answer on test 1):
#include <algorithm>

#include <iostream>

using namespace std;

long long a[200009];

int main() {

long long t;

cin >> t;

while (t--) {

long long n;

cin >> n;

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

cin >> a[i];

}

if (a[2] < a[1]) {

cout << "NO" << endl;

} else {

bool flag = true;

for (long long i = 3; i <= n; i++) {

if (a[i] < a[i - 1]) {

long long t = min(a[i - 2], a[i - 1]);

a[i - 2] -= t;

a[i - 1] -= t;

bool flag = true;

if (i == 3) {

if (a[2] < a[1] || a[3] < a[2]) flag = false;

} else {

for (int j = i - 3; j <= i; j++) {

if (a[j] < a[j - 1]) {

flag = false;

break;

}

}

}

}

}



if (flag) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <iostream>

using namespace std;

int a[200009];

int main() {

int t;

cin >> t;

while (t--) {

int n;

cin >> n;

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

cin >> a[i];

}

if (a[1] > a[2]) {

cout << "NO" << endl;

} else {

bool flag = true;

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

if (a[i] < a[i - 1]) {

int t = min(a[i - 2], a[i - 1]);

a[i - 2] -= t;

a[i - 1] -= t;

if (a[i] < a[i - 1]) {

flag = false;

break;

}

}

}



if (flag) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <algorithm>

#include <iostream>

using namespace std;

long long a[200009];

int main() {

long long t;

cin >> t;

while (t--) {

long long n;

cin >> n;

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

cin >> a[i];

}

if (a[2] < a[1]) {

cout << "NO" << endl;

} else {

bool flag = true;

for (long long i = 3; i <= n; i++) {

if (a[i] < a[i - 1]) {

long long t = min(a[i - 2], a[i - 1]);

a[i - 2] -= t;

a[i - 1] -= t;

bool flag = true;

if (i == 3) {

if (a[2] < a[1] || a[3] < a[2]) flag = false;

} else {

for (int j = i - 3; j <= i; j++) {

if (a[j] < a[j - 1]) {

flag = false;

break;

}

}

}

}

}



if (flag) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}

}

return 0;

}



Submission (verdict: Accepted):
#include <algorithm>

#include <iostream>

using namespace std;

long long a[200009];

int main() {

long long t;

cin >> t;

while (t--) {

long long n;

cin >> n;

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

cin >> a[i];

}

bool flag = true;

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

if (a[i] >= a[i - 1]) {

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

a[i - 1] = 0;

} else {

flag = false;

}

}



if (flag) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}



return 0;

}