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;
}