ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

int main(){
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        vector<int>a(n);
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        bool change = true;
        for(int i=0; i<n-2; i++){
            if(a[i] > a[i+1]){
                change = false;
                break;
            }else{
                a[i+1] -= a[i];
                a[i] = 0;
            }
        }
        if(!change){
            cout << "no" << endl;
        }else{
            cout << "yes" << endl;
        }
    }
}


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

int main(){
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        vector<int>a(n);
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        bool change = true;
        for(int i=0; i<n-1; i++){
            if(a[i] > a[i+1]){
                change = false;
                break;
            }else{
                a[i+1] -= a[i];
                a[i] = 0;
            }
        }
        if(!change){
            cout << "no" << endl;
        }else{
            cout << "yes" << endl;
        }
    }
}
Problem: 2060D - Subtract Min Sort
Language: Java 21


Submission (verdict: Wrong answer on test 2):


import java.util.Scanner;













public class SumTo {

    private static boolean  Solution(int[]a,int n){

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

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

                return false;

            }

        }

        return true;

        

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t=sc.nextInt();

        while(t-->0){

            int n=sc.nextInt();

            int[]a=new int[n];

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

                a[i]=sc.nextInt();

            }

            System.out.println(Solution(a,n)?"Yes":"NO");

        }

    }

}
Problem: 2060D - Subtract Min Sort
Language: Java 21

Previous submission (verdict: Time limit exceeded on test 8):


import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;













public class SumTo {

    private static boolean  Solution(int[]a,int n){

        List<Integer> al = new ArrayList<>();

        for (int num : a) {

            al.add(num);

        }

        while (al.size() > 1) {

            if (al.get(0) > al.get(1)) {

                return false;

            } else if (al.get(0) < al.get(1)) {

                al.set(1, al.get(1) - al.get(0)); // Update second element

                al.remove(0); // Remove the first element

            } else { // al.get(0) == al.get(1)

                al.remove(0); // Remove the first element

                al.remove(0); // Remove the (new) first element

            }

        }

        return true;

        

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t=sc.nextInt();

        while(t-->0){

            int n=sc.nextInt();

            int[]a=new int[n];

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

                a[i]=sc.nextInt();

            }

            System.out.println(Solution(a,n)?"Yes":"NO");

        }

    }

}



Submission (verdict: Accepted):


import java.util.Deque;

import java.util.LinkedList;

import java.util.Scanner;

import javax.print.DocPrintJob;













public class SumTo {

    private static boolean  Solution(int[]a,int n){

        Deque<Integer>dq=new LinkedList<>();

        for(int num:a){

            dq.add(num);

        }

        while(dq.size()>1){

            if(((LinkedList<Integer>) dq).get(0)>((LinkedList<Integer>) dq).get(1)){

                return false;

            }

            else if(((LinkedList<Integer>) dq).get(0)<((LinkedList<Integer>) dq).get(1)){

                int first = dq.removeFirst();

                int second = dq.removeFirst();

                dq.addFirst(second - first);



            }else{

                dq.pollFirst();

                dq.pollFirst();

            }

        }

        return true;

        

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t=sc.nextInt();

        while(t-->0){

            int n=sc.nextInt();

            int[]a=new int[n];

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

                a[i]=sc.nextInt();

            }

            System.out.println(Solution(a,n)?"Yes":"NO");

        }

    }

}
Problem: 2060D - Subtract Min Sort
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):


import java.util.Scanner;













public class SumTo {

    private static boolean  Solution(int[]a,int n){

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

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

                return false;

            }

        }

        return true;

        

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t=sc.nextInt();

        while(t-->0){

            int n=sc.nextInt();

            int[]a=new int[n];

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

                a[i]=sc.nextInt();

            }

            System.out.println(Solution(a,n)?"Yes":"NO");

        }

    }

}



Submission (verdict: Wrong answer on test 2):


import java.util.Scanner;













public class SumTo {

    private static boolean  Solution(int[]a,int n){

        if(n==2 && a[0]>a[1]){

            return false;



        }

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

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

                return false;

            }

        }

        return true;

        

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t=sc.nextInt();

        while(t-->0){

            int n=sc.nextInt();

            int[]a=new int[n];

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

                a[i]=sc.nextInt();

            }

            System.out.println(Solution(a,n)?"Yes":"NO");

        }

    }

}
Problem: 2060D - Subtract Min Sort
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):


import java.util.Scanner;













public class SumTo {

    private static boolean  Solution(int[]a,int n){

        if(n==2 && a[0]>a[1]){

            return false;



        }

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

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

                return false;

            }

        }

        return true;

        

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t=sc.nextInt();

        while(t-->0){

            int n=sc.nextInt();

            int[]a=new int[n];

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

                a[i]=sc.nextInt();

            }

            System.out.println(Solution(a,n)?"Yes":"NO");

        }

    }

}



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


import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;













public class SumTo {

    private static boolean  Solution(int[]a,int n){

        List<Integer> al = new ArrayList<>();

        for (int num : a) {

            al.add(num);

        }

        while (al.size() > 1) {

            if (al.get(0) > al.get(1)) {

                return false;

            } else if (al.get(0) < al.get(1)) {

                al.set(1, al.get(1) - al.get(0)); // Update second element

                al.remove(0); // Remove the first element

            } else { // al.get(0) == al.get(1)

                al.remove(0); // Remove the first element

                al.remove(0); // Remove the (new) first element

            }

        }

        return true;

        

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t=sc.nextInt();

        while(t-->0){

            int n=sc.nextInt();

            int[]a=new int[n];

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

                a[i]=sc.nextInt();

            }

            System.out.println(Solution(a,n)?"Yes":"NO");

        }

    }

}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


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

int main() {
    int n;
    cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; ++i) cin >> c[i];

    vector<int> cars(n);
    iota(cars.begin(), cars.end(), 1); // Initialize cars as [1, 2, ..., n]

    vector<pair<int, int>> overtakes;

    // Perform Bubble Sort to count overtakes
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - 1; ++j) {
            if (cars[j] > cars[j + 1]) {
                swap(cars[j], cars[j + 1]);
                overtakes.push_back({cars[j + 1], cars[j]});
            }
        }
    }

    // Output the number of overtakes and the list of overtakes
    cout << overtakes.size() << endl;
    for (const auto& overtake : overtakes) {
        cout << overtake.first << " " << overtake.second << endl;
    }

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

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

int main() {
    int n;
    cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; ++i) cin >> c[i];

    vector<int> cars(n);
    iota(cars.begin(), cars.end(), 1); // Initialize cars as [1, 2, ..., n]

    vector<pair<int, int>> overtakes;

    // Perform Bubble Sort to count overtakes
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - 1; ++j) {
            if (cars[j] > cars[j + 1]) {
                swap(cars[j], cars[j + 1]);
                overtakes.push_back({cars[j + 1], cars[j]});
            }
        }
    }

    // Output the number of overtakes and the list of overtakes
    cout << overtakes.size() << endl;
    for (const auto& overtake : overtakes) {
        cout << overtake.first << " " << overtake.second << endl;
    }

    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> c(n); // Final order of the cars
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }

    vector<int> initial_order(n);
    for (int i = 0; i < n; ++i) {
        initial_order[i] = i + 1;
    }

    vector<pair<int, int>> overtakes;

    // Simulate overtakes to reach the final order from initial order
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - 1; ++j) {
            if (initial_order[j] > initial_order[j + 1]) {
                overtakes.push_back({initial_order[j + 1], initial_order[j]});
                swap(initial_order[j], initial_order[j + 1]);
            }
        }
    }

    cout << overtakes.size() << endl;
    for (auto& overtake : overtakes) {
        cout << overtake.first << " " << overtake.second << endl;
    }

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> c(n); // Final order of the cars
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }

    vector<int> initial_order(n);
    for (int i = 0; i < n; ++i) {
        initial_order[i] = i + 1;
    }

    vector<pair<int, int>> overtakes;

    // Simulate overtakes to reach the final order from initial order
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - 1; ++j) {
            if (initial_order[j] > initial_order[j + 1]) {
                overtakes.push_back({initial_order[j + 1], initial_order[j]});
                swap(initial_order[j], initial_order[j + 1]);
            }
        }
    }

    cout << overtakes.size() << endl;
    for (auto& overtake : overtakes) {
        cout << overtake.first << " " << overtake.second << endl;
    }

    return 0;
}


Submission (verdict: Accepted):
#include <iostream>
using namespace std;
const int N=230000;
int n,a[N],ans,vis[N];
struct fa{
	int x,y;
}as[N*20];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		vis[a[i]]=1;
		for(int j=a[i]+1;j<=n;j++) if(!vis[j]) as[++ans]={j,a[i]};
		for(int j=n;j>=1;j--) if(!vis[j]) as[++ans]={a[i],j};
	}
	cout<<ans<<endl;
	for(int i=1;i<=ans;i++){
		cout<<as[i].x<<' '<<as[i].y<<endl;
	}
	return 0;
}
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;
#define ll long long
#define vi(v,n) vector<int>(v)((n)); for(int i=0;i<(n);i++){cin>>(v)[i];}
#define vl(v,n) vector<long long>(v)((n)); for(int i=0;i<(n);i++){cin>>(v)[i];}
#define srt(v) sort((v).begin(),(v).end())
#define srtr(v) sort((v).begin(),(v).end(),greater<>())
#define pb push_back
#define nl "\n"
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define setbits(x) __builtin_popcountll(x)
#define For(i,b) for(int (i)=0;(i)<(b);(i)++)
#define ff first
#define ss second
#define test ll x86; cin>>x86; while(x86--)
#define all(x) x.begin(),x.end()
#define speed ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
#define pvec(v) for(auto it:(v)){cout<<it<<" ";}cout<<nl
#define mii(a) map<int,int>(a)
#define miir(a) map<int,int,greater<>>(a)  
#define mll(a) map<ll,ll>(a)
#define mllr(a) map<ll,ll,greater<>>(a)
#define pmap(m) for(auto it:(m)){cout<<it.ff<<" "<<it.ss<<nl;}cout<<nl
#define ppvec(v) for(auto it:(v)){cout<<it.ff<<" "<<it.ss<<nl;}cout<<nl
 
const int INF = 1e9+5;
const int mod=1e9+7;


void solve() {
    int n;
    cin>>n;
    vi(a, n);
    ll ans=0;
    if(n==1){
        cout<<a[0]<<endl;
        return;
    }
    for(int i=0; i<n-1; i++){
        ll sum1=0;
        ll sum=0;
        ll rev=0;
        vector<int> v=a;
        for(int j=0; j<a.size(); j++){
            sum1+=a[j];
        }
        for(int j=1; j<a.size(); j++){
            sum+=(a[j]-a[j-1]);
            a[j-1]=a[j]-a[j-1];
        }
        reverse(v.begin(), v.end());
        for(int j=1; j<a.size(); j++){
            rev+=(v[j]-v[j-1]);
            v[j-1]=v[j]-v[j-1];
        }
        vector<int> b(a.size()-1);
        ans=max({sum1, sum, rev});
        if(rev>sum){
            b.assign(v.begin(), v.end() - 1);
        }
        else{
            b.assign(a.begin(), a.end() - 1);
        }
        a=b;
    }
    cout<<ans<<endl;
}
  
int main() {
    test
    solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

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

string solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int &x : a) cin >> x;
    for (int &x : b) cin >> x;
    
    long long sum_a = accumulate(a.begin(), a.end(), 0LL);
    long long sum_b = accumulate(b.begin(), b.end(), 0LL);
    if (sum_a != sum_b) return "No";
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    multiset<int> ms(a.begin(), a.end());
    
    for (int i = m - 1; i >= 0; --i) {
        int s = b[i];
        if (ms.empty()) return "No";
        auto it = ms.find(s);
        if (it != ms.end()) {
            ms.erase(it);
            continue;
        }
        
        // Need to form s by merging
        long long sum_needed = s;
        int max_allowed = (s + 1) / 2; // max allowed in the group
        vector<int> group;
        bool possible = true;
        
        while (sum_needed > 0) {
            int current_limit = min(sum_needed, (long long)max_allowed);
            auto y_it = ms.upper_bound(current_limit);
            if (y_it == ms.begin()) {
                possible = false;
                break;
            }
            --y_it;
            int y = *y_it;
            if (y > max_allowed) {
                possible = false;
                break;
            }
            group.push_back(y);
            sum_needed -= y;
            ms.erase(y_it);
        }
        
        if (!possible || sum_needed != 0) {
            return "No";
        }
        
        int group_max = *max_element(group.begin(), group.end());
        if (group_max > max_allowed) {
            return "No";
        }
    }
    
    return "Yes";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        cout << solve() << '\n';
    }
    
    return 0;
}

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

string solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int &x : a) cin >> x;
    for (int &x : b) cin >> x;

    long long sum_a = accumulate(a.begin(), a.end(), 0LL);
    long long sum_b = accumulate(b.begin(), b.end(), 0LL);
    if (sum_a != sum_b) return "No";

    multiset<int> a_ms(a.begin(), a.end());
    priority_queue<int> b_pq;
    for (int x : b) b_pq.push(x);

    int allowed_splits = n - m;

    while (!b_pq.empty()) {
        int x = b_pq.top();
        b_pq.pop();

        auto it = a_ms.find(x);
        if (it != a_ms.end()) {
            a_ms.erase(it);
        } else {
            if (allowed_splits <= 0) return "No";
            int split1 = (x + 1) / 2;
            int split2 = x / 2;
            b_pq.push(split1);
            b_pq.push(split2);
            allowed_splits--;
        }
    }

    return (a_ms.empty() && allowed_splits == 0) ? "Yes" : "No";
}

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

    int t;
    cin >> t;
    while (t--) {
        cout << solve() << '\n';
    }

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


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

string solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int &x : a) cin >> x;
    for (int &x : b) cin >> x;
    
    long long sum_a = accumulate(a.begin(), a.end(), 0LL);
    long long sum_b = accumulate(b.begin(), b.end(), 0LL);
    if (sum_a != sum_b) return "No";
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    multiset<int> ms(a.begin(), a.end());
    
    for (int i = m-1; i >= 0; --i) {
        int s = b[i];
        if (ms.empty()) return "No";
        auto it = ms.find(s);
        if (it != ms.end()) {
            ms.erase(it);
            continue;
        }
        if (ms.empty() || *prev(ms.end()) > s) return "No";
        
        long long current = 0;
        int max_elem = 0;
        vector<int> temp;
        while (current < s) {
            if (ms.empty()) return "No";
            auto it = prev(ms.end());
            int x = *it;
            ms.erase(it);
            current += x;
            temp.push_back(x);
            max_elem = max(max_elem, x);
        }
        if (current != s) return "No";
        if (max_elem > (s - max_elem) + 1) return "No";
    }
    
    return "Yes";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        cout << solve() << '\n';
    }
    
    return 0;
}
Problem: 2050D - Digital string maximization
Language: PyPy 3-64

Previous submission (verdict: Runtime error on test 1):
n = int(input())

for i in range(n):

s= list(map(int, input().split('')))

g = len(s)

for i in range(1,g):

for j in range(0, s[i]):

if(i-j-10):

break

if(s[i-j]-1 > s[i-j-1]):

temp = s[i-j-1]

s[i-j-1] = s[i-j]-1

s[i-j] = temp

else:

break

print(string(s))

Submission (verdict: Runtime error on test 1):
n = int(input())

for i in range(n):

s= list(map(int, input().split('')))

g = len(s)

for i in range(1,g):

for j in range(0, s[i]):

if(i-j-1):

break

if(s[i-j]-1 > s[i-j-1]):

temp = s[i-j-1]

s[i-j-1] = s[i-j]-1

s[i-j] = temp

else:

break

print(string(s))
Problem: 2050D - Digital string maximization
Language: PyPy 3-64

Previous submission (verdict: Runtime error on test 1):
n = int(input())

for i in range(n):

s= list(map(int, input().split('')))

g = len(s)

for i in range(1,g):

for j in range(0, s[i]):

if(i-j-1):

break

if(s[i-j]-1 > s[i-j-1]):

temp = s[i-j-1]

s[i-j-1] = s[i-j]-1

s[i-j] = temp

else:

break

print(string(s))

Submission (verdict: Accepted):
n = int(input())

for x in range(n):

s= list(map(int, input()))

g = len(s)

for i in range(1,g):

for j in range(0, s[i]):

if(i-j-1 < 0):

break

if(s[i-j]-1 > s[i-j-1]):

temp = s[i-j-1]

s[i-j-1] = s[i-j]-1

s[i-j] = temp

else:

break

result = ''.join(map(str,s))

print(result)
Problem: 2050D - Digital string maximization
Language: PyPy 3-64


Submission (verdict: Runtime error on test 1):
n = int(input())

for i in range(n):

s= list(map(int, input().split('')))

g = len(s)

for i in range(1,g):

for j in range(0, s[i]):

if(i-j-10):

break

if(s[i-j]-1 > s[i-j-1]):

temp = s[i-j-1]

s[i-j-1] = s[i-j]-1

s[i-j] = temp

else:

break

print(string(s))
Problem: 2062C - Cirno and Operations
Language: Python 3


Submission (verdict: Runtime error on test 1):
from itertools import pairwise

numTestCases = int(input())
while numTestCases > 0:
    numTestCases -= 1
    int(input())
    a = [int(x) for x in input().split()]
    res = sum(a)
    while len(a) > 1:
        if a[-1] < a[0]:
            a = list(reversed(a))
        res = max(res, a[-1] - a[0])
        a = [y-x for x,y in pairwise(a)]
    res = max(res, a[0])
    print(res)
Problem: 2062C - Cirno and Operations
Language: Python 3

Previous submission (verdict: Runtime error on test 1):
from itertools import pairwise

numTestCases = int(input())
while numTestCases > 0:
    numTestCases -= 1
    int(input())
    a = [int(x) for x in input().split()]
    res = sum(a)
    while len(a) > 1:
        if a[-1] < a[0]:
            a = list(reversed(a))
        res = max(res, a[-1] - a[0])
        a = [y-x for x,y in pairwise(a)]
    res = max(res, a[0])
    print(res)


Submission (verdict: Runtime error on test 1):
from itertools import pairwise

numTestCases = int(input())
while numTestCases > 0:
    numTestCases -= 1
    int(input())
    a = [int(x) for x in input().split()]
    res = sum(a)
    while len(a) > 1:
        if a[-1] < a[0]:
            a = list(reversed(a))
        res = max(res, a[-1] - a[0])
        a = [y-x for x,y in pairwise(a)]
    print(res)
Problem: 2062C - Cirno and Operations
Language: PyPy 3-64

Previous submission (verdict: Runtime error on test 1):
from itertools import pairwise

numTestCases = int(input())
while numTestCases > 0:
    numTestCases -= 1
    int(input())
    a = [int(x) for x in input().split()]
    res = sum(a)
    while len(a) > 1:
        if a[-1] < a[0]:
            a = list(reversed(a))
        res = max(res, a[-1] - a[0])
        a = [y-x for x,y in pairwise(a)]
    print(res)


Submission (verdict: Accepted):
from itertools import pairwise

numTestCases = int(input())
while numTestCases > 0:
    numTestCases -= 1
    int(input())
    a = [int(s) for s in input().split()]
    res = sum(a)
    while len(a) > 1:
        if a[-1] < a[0]:
            a = list(reversed(a))
        res = max(res, a[-1] - a[0])
        a = [y-x for x,y in pairwise(a)]
    print(res)