I was on an Instant high when I solved the first 2 in less than 7 mins. Then I overlooked this problem and what I misunderstood was our Aim is to put equal sums on both sides, such that total weight must be greater than or equal to the W. I immediately searched for the subset sum problem (my bad), wasted much time modifying the DP approaches found online. Later realised this would fail as the constraints are much higher where DP wouldn’t pass. But noticed that I can easily solve for 1st Subtask - Coded for those 30 points and boom rank was 20. After having dinner (when lunchtime was going on) I came back and saw the rank go above 1000. I slapped myself for not looking at this problem carefully and immediately solved it for 100. Still rank was increasing exponentially. Took a deep breath and solved the remaining problems partially. This way I was able to prevent the fall of ratings .
Btw, NICE problems but it would have been better if the first three problems didn’t have the same difficulty, it is like the first three problems are just a cakewalk and the immediate next problem is super difficult for me.
Umm So the algo is correct,
the thing is the questions should have been more clear in that what they meant from symmetric, I thought that just the torque should be zero or weights should be equal
Your solution is mostly similar to that of mine…i think what mistake you have done is that the iteration which you have used like think about cases if weights are 10,10,10 your code will consider the middle 10 two times… because bcz here if it is a array,then a[0] = a[1] and a[1] = a[2]… but we do not have to do that here. Clearly from this array only two weights of 10 can be used… not all three… So if we select a pair we need to jump not one but two place as when a pair is selected another element comes with it already… If you will think about these type of cases then you can figure out the mistake…Thanks
int main() {
int T;
cin>>T;
while(T–)
{
int N,W,Wr,i,temp,sum=0;
cin>>N>>W>>Wr;
int wr[N];
sum+=Wr;
for(i=0;i<N;i++)
cin>>wr[i];
if(Wr>=W)
cout<<“YES”<<endl;
else
{
i=0;
sort(wr,wr+N);
while(i<N)
{
int count=0;
temp=wr[i];
while(wr[i]==temp)
{
count++;
i++;
if(i>=N)
break;
}
if((count%2)==0)
sum+=(count*temp);
else
sum+=(count-1)*temp;
}
if(sum>=W)
cout<<“YES”<<endl;
else
cout<<“NO”<<endl;
}
}
return 0;
}
Could someone please tell what’s wrong in this code. It’s running on some other compilers but not on CodeChef. I am getting runtime error.
I HAVE DONE THIS YESTERDAY AFTER READING THE QUESTION INCORRECTLY AND MISSED THE WORD " AT LEAST ". GO THROUGHT THE CODE AND IF POSSIBLE TRY TO HACK MY CODE. I HAVE NOT TESTED IT TO VARITY OF TEST CASES. HERE IS THE CODE.