Help me in solving SAVEKONO problem

My issue

What is wrong with my code? It’s giving the correct answer on the given sample input but it fails somewhere when the online judge checks it.

My code

#include <iostream>
#include <set>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    multiset<int> A;
	    int temp,N,Z;
	    cin>>N>>Z;
	    for (int i = 0; i < N; i++) {
	        cin>>temp;
	        A.insert(temp);
	    }
	    int attacks=0;
	    for(auto it=A.rbegin();it!=A.rend();++it){
	        if(Z<=0)
	        break;
	        else
	        {
	           // cout<<"Z="<<Z<<" ";
	            int X=*it;
	            Z=Z-X;
	            A.erase(X);
	            A.insert(X/2);
	            attacks++;
	        }
	    }
	    cout<<attacks;
	}
	return 0;
}

Learning course: STLs in C++
Problem Link: Save Konoha Practice Problem in STLs in C++ - CodeChef