Mike and task packages

Hey guys, for this question my approach was to sort the array and first make sure all half tasks are done(in sorted order). Next complete tasks (again in sorted order). Here is my code. Whats wrong with it?

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

int main() {
	// your code goes here
	long long n,x;
	cin>>n>>x;
	int nw =0;
	long long count =0;
    	long a[1000000],b[1000000];
    	for(int i=0;i<n;i++)cin>>a[i];
    	sort(a,a+n);
    	for(int i=0;i<n;i++)b[i]=a[i];
    	for(int i=0;((count+(a[i])/2)<=x)&&i<n;i++)
    	{
    		count=count+a[i]/2;
    		a[i]-=(a[i])/2;

		nw++;//not wrong
		
	}
	int succ = 0;
	for(int i=0;i<n&&((count+a[i])<=x);i++)
	{
		count+=a[i];
		a[i]=0;
		succ++;
	}
	int wrong = n-nw;
	cout<<wrong<<" "<<succ;
	return 0;
}

Your approach is right .Even my approach was also same, but you missed a very small thing , " a package is failed if mike solved less than half of the tasks in it "ie for example if no of the tasks are in a package are 5 then mike must solved atleast 3 tasks so that in that package he is not failed , and acc. to your solution ,even if he solves 2 tasks, he is not failed .

this is my solution:http://www.codechef.com/viewsolution/3140306

//