ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


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

int findMSB(int n) {
    if (n == 0) return 0;
    return (31 - __builtin_clz(n));
}

void solve() {
    int n,m;
    cin>>n>>m;
    multiset<int> mu1;
    multiset<int> mu2;
 for(int i=0;i<n;i++){
    int x;
    cin>>x;
    mu1.insert(x);
     
 }
 for(int i=0;i<m;i++){
    int x;
    cin>>x;
    mu2.insert(x);
     
 }

while(!mu1.empty() && !mu2.empty()){
    //   auto it1=mu1.begin();
    // cout<<mu1.size()<<" "<<mu2.size()<<" ";
    if(mu2.size()>mu1.size()){
        cout<<"NO";
        // cout<<"HGF";
        return ;
    }
      auto it2=mu2.begin();
      auto it1=mu1.find(*it2);
      if(mu1.find(*it2)!=mu1.end()){
        mu1.erase(it1);
        mu2.erase(it2);
      }
      else{
         int y=*it2;
         mu2.erase(y);
         if(y%2==0){
            mu2.insert(y/2);
            mu2.insert(y/2);
         }
         else{
            mu2.insert((y+1)/2);
            mu2.insert(y/2);
         }
      }
}
if(mu1.empty() && mu2.empty()){
    cout<<"YES";
    return ;
}
cout<<"NO";



}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
        cout<<endl;
    }
}
Problem: 2050B - Transfusion
Language: Python 3

Previous submission (verdict: Wrong answer on test 1):
t = int(input())

for i in range(t):

    n = int(input())

    inputs = list(map(int, input().split()))

    even_sum = 0

    odd_sum = 0

    for i in range(n):

        if i%2 == 0:

            even_sum += inputs[i]

        else:

            odd_sum += inputs[i]

    if n%2 == 1:

        if even_sum/(n//2+1) == odd_sum*(n-n//2-1):

            print("YES")

        else:

            print("NO")

    else:

        if even_sum/(n//2) == odd_sum*(n-n//2):

            print("YES")

        else:

            print("NO")

Submission (verdict: Wrong answer on test 1):
t = int(input())

for i in range(t):

    n = int(input())

    inputs = list(map(int, input().split()))

    even_sum = 0

    odd_sum = 0

    for i in range(n):

        if i%2 == 0:

            even_sum += inputs[i]

        else:

            odd_sum += inputs[i]

    if n%2 == 1:

        if even_sum/(n//2+1) == odd_sum*(n-n//2-1):

            print("YES")

        else:

            print("NO")

    else:

        if even_sum == odd_sum:

            print("YES")

        else:

            print("NO")
Problem: 2050B - Transfusion
Language: Python 3

Previous submission (verdict: Wrong answer on test 1):
t = int(input())

for i in range(t):

    n = int(input())

    inputs = list(map(int, input().split()))

    even_sum = 0

    odd_sum = 0

    for i in range(n):

        if i%2 == 0:

            even_sum += inputs[i]

        else:

            odd_sum += inputs[i]

    if n%2 == 1:

        if even_sum/(n//2+1) == odd_sum*(n-n//2-1):

            print("YES")

        else:

            print("NO")

    else:

        if even_sum == odd_sum:

            print("YES")

        else:

            print("NO")

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

for i in range(t):

    n = int(input())

    inputs = list(map(int, input().split()))

    even_sum = 0

    odd_sum = 0

    for i in range(n):

        if i%2 == 0:

            even_sum += inputs[i]

        else:

            odd_sum += inputs[i]

    if n%2 == 0:

        even = odd = n/2

    else:

        even = n//2+1

        odd = n - even

    if even_sum/even == int(even_sum/even) and odd_sum/odd == int(odd_sum/odd):

        if even_sum/even == odd_sum/odd:

            print("YES")

        else:

            print("NO")

    else:

        print("NO")
Problem: 2050B - Transfusion
Language: Python 3


Submission (verdict: Wrong answer on test 1):
t = int(input())

for i in range(t):

    n = int(input())

    inputs = list(map(int, input().split()))

    even_sum = 0

    odd_sum = 0

    for i in range(n):

        if i%2 == 0:

            even_sum += inputs[i]

        else:

            odd_sum += inputs[i]

    if n%2 == 1:

        if even_sum/(n//2+1) == odd_sum*(n-n//2-1):

            print("YES")

        else:

            print("NO")

    else:

        if even_sum/(n//2) == odd_sum*(n-n//2):

            print("YES")

        else:

            print("NO")
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


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

#define fast_io ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)

void solve() {
    int n, m;
    cin >> n >> m;

    vector<int> a(n);
    multiset<int> b;

    for (int &x : a) cin >> x;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        b.insert(x);
    }

    // Sort `a` in descending order to always try to match the largest element first
    sort(a.rbegin(), a.rend());

    for (int x : a) {
        auto it = b.lower_bound(x);  // Find smallest element >= x
        if (it == b.end()) {         // No valid element found
            cout << "No\n";
            return;
        }
        b.erase(it);  // Remove used element
    }

    cout << "Yes\n";
}

int main() {
    fast_io;
    cout << fixed << setprecision(10);

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

    return 0;
}
Problem: 2063B - Subsequence Update
Language: Java 8


Submission (verdict: Wrong answer on test 1):
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while (t-- > 0) {
            int n = sc.nextInt();
            int l = sc.nextInt();  // 1-based index
            int r = sc.nextInt();  // 1-based index
            int[] arr = new int[n + 1];

            for (int i = 1; i <= n; i++) arr[i] = sc.nextInt();

            int max = 0;

            // Calculate initial max from l to r
            for (int i = l; i <= r; i++) max += arr[i];

            PriorityQueue<Integer> pq = new PriorityQueue<>();

            int sum = 0;

            // First window sum
            for (int i = 1; i <= r; i++) pq.add(arr[i]);
            int tl = l, tr = r;

            while (tr - tl + 1 > 0) {
                sum += pq.poll();
                tl++;
            }

            max = Math.max(max, sum);
            pq.clear();

            for (int i = l; i <= n; i++) pq.add(arr[i]);

            System.out.println(max);  // Final result for each test case
        }

        sc.close();
    }
}
Problem: 2063B - Subsequence Update
Language: Java 8

Previous submission (verdict: Wrong answer on test 1):
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while (t-- > 0) {
            int n = sc.nextInt();
            int l = sc.nextInt();  // 1-based index
            int r = sc.nextInt();  // 1-based index
            int[] arr = new int[n + 1];

            for (int i = 1; i <= n; i++) arr[i] = sc.nextInt();

            int max = 0;

            // Calculate initial max from l to r
            for (int i = l; i <= r; i++) max += arr[i];

            PriorityQueue<Integer> pq = new PriorityQueue<>();

            int sum = 0;

            // First window sum
            for (int i = 1; i <= r; i++) pq.add(arr[i]);
            int tl = l, tr = r;

            while (tr - tl + 1 > 0) {
                sum += pq.poll();
                tl++;
            }

            max = Math.max(max, sum);
            pq.clear();

            for (int i = l; i <= n; i++) pq.add(arr[i]);

            System.out.println(max);  // Final result for each test case
        }

        sc.close();
    }
}


Submission (verdict: Wrong answer on test 1):
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();  // number of test cases
        while (t-- > 0) {
            // Read n, l, r
            int n = sc.nextInt();
            int l = sc.nextInt();  // 1-based index
            int r = sc.nextInt();  // 1-based index

            // Read array arr
            int[] arr = new int[n + 1];  // Using n+1 to handle 1-based indexing
            for (int i = 1; i <= n; i++) {
                arr[i] = sc.nextInt();
            }

            int max = 0;

            // Step 1: Calculate the sum for the range [l, r]
            for (int i = l; i <= r; i++) {
                max += arr[i];
            }

            // Step 2: Use priority queue to store the elements in the range [1, r] 
            PriorityQueue<Integer> pq = new PriorityQueue<>();
            for (int i = 1; i <= r; i++) {
                pq.add(arr[i]);
            }

            int sum = 0;
            int tl = l;
            int tr = r;

            // Step 3: Add elements to sum from the priority queue and calculate the new range
            while (tr - tl + 1 > 0) {
                sum += pq.poll();  // Poll the minimum element
                tl++;  // Increment the left boundary
            }

            max = Math.max(max, sum);  // Track the maximum sum obtained
            pq.clear();

            // Step 4: Add all elements from l to n into the priority queue
            for (int i = l; i <= n; i++) {
                pq.add(arr[i]);
            }

            // Output the result for the current test case
            System.out.println(max);
        }
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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

string solve(string s) {
    for(int i = 0; i < s.length() - 1; ++i) {
        int max = -1;
        int max_index = -1;
        for(int j = i; j <= i + 9 && j < s.length(); ++j) {
            int d = s[j] - '0';
            if(d - (j - i) > max) {
                max = d;
                max_index = j;
            }
        }

        s[max_index] = (char) (s[max_index] - '0' - (max_index - i) + '0');
        for(int j = max_index; j > i; --j) {
            char temp = s[j - 1];
            s[j - 1] = s[j];
            s[j] = temp;
        }
    }
    return s;
}

int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; ++i) {
        string s;
        cin >> s;
        cout << solve(s);
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

string solve(string s) {
    for(int i = 0; i < s.length() - 1; ++i) {
        int max = -1;
        int max_index = -1;
        for(int j = i; j <= i + 9 && j < s.length(); ++j) {
            int d = s[j] - '0';
            if(d - (j - i) > max) {
                max = d;
                max_index = j;
            }
        }

        s[max_index] = (char) (s[max_index] - '0' - (max_index - i) + '0');
        for(int j = max_index; j > i; --j) {
            char temp = s[j - 1];
            s[j - 1] = s[j];
            s[j] = temp;
        }
    }
    return s;
}

int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; ++i) {
        string s;
        cin >> s;
        cout << solve(s) << "\n";
    }
}

Submission (verdict: Accepted):
#include <iostream>
#include <queue>
using namespace std;

string solve(string s) {
    for(int i = 0; i < s.length() - 1; ++i) {
        int max = -1;
        int max_index = -1;
        for(int j = i; j <= i + 9 && j < s.length(); ++j) {
            int d = s[j] - '0';
            if(d - (j - i) > max) {
                max = d - (j - i);
                max_index = j;
            }
        }

        s[max_index] = (char) (s[max_index] - '0' - (max_index - i) + '0');
        for(int j = max_index; j > i; --j) {
            char temp = s[j - 1];
            s[j - 1] = s[j];
            s[j] = temp;
        }
    }
    return s;
}

int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; ++i) {
        string s;
        cin >> s;
        cout << solve(s) << "\n";
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

string solve(string s) {
    for(int i = 0; i < s.length() - 1; ++i) {
        int max = -1;
        int max_index = -1;
        for(int j = i; j <= i + 9 && j < s.length(); ++j) {
            int d = s[j] - '0';
            if(d - (j - i) > max) {
                max = d;
                max_index = j;
            }
        }

        s[max_index] = (char) (s[max_index] - '0' - (max_index - i) + '0');
        for(int j = max_index; j > i; --j) {
            char temp = s[j - 1];
            s[j - 1] = s[j];
            s[j] = temp;
        }
    }
    return s;
}

int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; ++i) {
        string s;
        cin >> s;
        cout << solve(s);
    }
}

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

string solve(string s) {
    for(int i = 0; i < s.length() - 1; ++i) {
        int max = -1;
        int max_index = -1;
        for(int j = i; j <= i + 9 && j < s.length(); ++j) {
            int d = s[j] - '0';
            if(d - (j - i) > max) {
                max = d;
                max_index = j;
            }
        }

        s[max_index] = (char) (s[max_index] - '0' - (max_index - i) + '0');
        for(int j = max_index; j > i; --j) {
            char temp = s[j - 1];
            s[j - 1] = s[j];
            s[j] = temp;
        }
    }
    return s;
}

int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; ++i) {
        string s;
        cin >> s;
        cout << solve(s) << "\n";
    }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

#define ll long long



void solve() 

{

  

   int n,l,r;

   cin >> n >> l >> r;

   vector<int>v(n);

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

   {

    cin >> v[i];

   }

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



   ll ans=0;

   for(int i=0;i<(r-l+1);i++)

   {

    ans=ans+v[i];

   }

   cout << ans << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin >> t;

    while (t--) solve();



    return 0;

}



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

using namespace std;

#define ll long long



void solve() 

{

    int n, l, r;

    cin >> n >> l >> r;

    vector<int> v(n + 1);

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

        cin >> v[i];

    }



    // Split segments

    vector<int> bl(v.begin() + 1, v.begin() + l);  // Before l

    vector<int> br(v.begin() + r + 1, v.end());    // After r

    vector<int> need(v.begin() + l, v.begin() + r + 1);  // Between l and r



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

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

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



    // Calculate minimum sums

    int ans1 = 0, ans2 = 0;

    int sl = 0, sn = 0;

    int k = r - l + 1;



    // Calculate ans1

    while (k--) {

        if (sl < bl.size() && (sn >= need.size() || bl[sl] <= need[sn])) {

            ans1 += bl[sl++];

        } else {

            ans1 += need[sn++];

        }

    }



    k = r - l + 1;

    int sr = 0;

    sn = 0;



    // Calculate ans2

    while (k--) {

        if (sr < br.size() && (sn >= need.size() || br[sr] <= need[sn])) {

            ans2 += br[sr++];

        } else {

            ans2 += need[sn++];

        }

    }



    cout << min(ans1, ans2) << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin >> t;

    while (t--) solve();



    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

#define ll long long



void solve() 

{

    int n, l, r;

    cin >> n >> l >> r;

    vector<int> v(n + 1);

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

        cin >> v[i];

    }



    // Split segments

    vector<int> bl(v.begin() + 1, v.begin() + l);  // Before l

    vector<int> br(v.begin() + r + 1, v.end());    // After r

    vector<int> need(v.begin() + l, v.begin() + r + 1);  // Between l and r



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

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

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



    // Calculate minimum sums

    int ans1 = 0, ans2 = 0;

    int sl = 0, sn = 0;

    int k = r - l + 1;



    // Calculate ans1

    while (k--) {

        if (sl < bl.size() && (sn >= need.size() || bl[sl] <= need[sn])) {

            ans1 += bl[sl++];

        } else {

            ans1 += need[sn++];

        }

    }



    k = r - l + 1;

    int sr = 0;

    sn = 0;



    // Calculate ans2

    while (k--) {

        if (sr < br.size() && (sn >= need.size() || br[sr] <= need[sn])) {

            ans2 += br[sr++];

        } else {

            ans2 += need[sn++];

        }

    }



    cout << min(ans1, ans2) << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin >> t;

    while (t--) solve();



    return 0;

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
void solve() 
{
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
 
   
    vector<ll> bl(v.begin() + 1, v.begin() + l);  // Before l
    vector<ll> br(v.begin() + r + 1, v.end());    // After r
    vector<ll> need(v.begin() + l, v.begin() + r + 1);  // Between l and r
 
    sort(bl.begin(), bl.end());
    sort(br.begin(), br.end());
    sort(need.begin(), need.end());
 
 
    ll ans1 = 0, ans2 = 0;
    ll sl = 0, sn = 0;
    ll k = r - l + 1;
 
  
    while (k--) {
        if (sl < bl.size() && (sn >= need.size() || bl[sl] <= need[sn])) {
            ans1 += bl[sl++];
        } else {
            ans1 += need[sn++];
        }
    }
 
    k = r - l + 1;
    ll sr = 0;
    sn = 0;
 
  
    while (k--) {
        if (sr < br.size() && (sn >= need.size() || br[sr] <= need[sn])) {
            ans2 += br[sr++];
        } else {
            ans2 += need[sn++];
        }
    }
 
    cout << min(ans1, ans2) << endl;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t;
    cin >> t;
    while (t--) solve();
 
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using namespace std;

#define ll long long



void solve() 

{

  

   int n,l,r;

   cin >> n >> l >> r;

   vector<int>v(n);

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

   {

    cin >> v[i];

   }

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



   ll ans=0;

   for(int i=0;i<(r-l+1);i++)

   {

    ans=ans+v[i];

   }

   cout << ans << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin >> t;

    while (t--) solve();



    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;

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

    while (t--)
    {
        int n, k;
        cin >> n >> k; 
        int arr[n];

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

        
        unordered_map<int, int> freq;
        for (int num : arr) {
            freq[num]++;
        }

        
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
        for (const auto& entry : freq) {
            pq.push({entry.second, entry.first});
        }

        
        int count = 0;
        while (k > 0 && !pq.empty()) {
            pair<int, int> top = pq.top();
            pq.pop();

            int temp = min(top.first, k);
            k -= temp;

            if (temp < top.first) {
                pq.push({top.first - temp, top.second});
                break;
            }
        }
        if(pq.empty())
        count = 1;
        
        while (!pq.empty()) {
            pq.pop();
            count++;
        }

        cout << count << endl;
    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    long long t;
    cin >> t; 

    while (t--)
    {
        long long n, k;
        cin >> n >> k; 
        long long arr[n];

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

        
        unordered_map<long long, long long> freq;
        for (long long num : arr) {
            freq[num]++;
        }

        
        priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq;
        for (const auto& entry : freq) {
            pq.push({entry.second, entry.first});
        }

        
        long long count = 0;
        while (k > 0 && !pq.empty()) {
            pair<long long, long long> top = pq.top();
            pq.pop();

            long long temp = min(top.first, k);
            k -= temp;

            if (temp < top.first) {
                pq.push({top.first - temp, top.second});
                break;
            }
        }
        if(pq.empty())
        count = 1;
        
        while (!pq.empty()) {
            pq.pop();
            count++;
        }

        cout << count << 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;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    long long t;
    cin >> t; 

    while (t--)
    {
        long long n, k;
        cin >> n >> k; 
        long long arr[n];

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

        
        unordered_map<long long, long long> freq;
        for (long long num : arr) {
            freq[num]++;
        }

        
        priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq;
        for (const auto& entry : freq) {
            pq.push({entry.second, entry.first});
        }

        
        long long count = 0;
        while (k > 0 && !pq.empty()) {
            pair<long long, long long> top = pq.top();
            pq.pop();

            long long temp = min(top.first, k);
            k -= temp;

            if (temp < top.first) {
                pq.push({top.first - temp, top.second});
                break;
            }
        }
        if(pq.empty())
        count = 1;
        
        while (!pq.empty()) {
            pq.pop();
            count++;
        }

        cout << count << endl;
    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    long long t;
    cin >> t; 

    while (t--)
    {
        long long n, k;
        cin >> n >> k; 
        long long arr[n];

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

        
        unordered_map<long long, long long> freq;
        for (long long num : arr) {
            freq[num]++;
        }
        
        vector<pair<long,long>>p;
        for(auto it : freq)
        {
               p.push_back({it.second,it.first});
        }
        sort(p.begin(),p.end());
        
        long long count = p.size();
        for(auto it:p)
        {
               if(k>=it.first)
               {
                     k-=it.first;
                     count--;
               }
               else
               {
                     break;
               }
        }
        if(count<=0)
        cout<<1<<endl;
        else
        cout << count << endl;
        
    }

    return 0;
}