Why i am getting wrong answer in bench press?

{
// your code goes here

int T;
cin>>T;
while(T!=0)
{
    int N,W,Wr,i,o=0,k,d,newwt=0;
    cin>>N>>W>>Wr;
    
    if(Wr>W)
    {
    o=1;
    
    }
    
    int w[N];
    for(i=0;i<N;i++)
    cin>>w[i]; 
    
    k=w[0];
    for(i=0;i<N;i++)
    k=max(k,w[i]);
    
     int count[k+1]={0};
     for(i=0;i<N;i++)
     count[w[i]]++;
     
     for(i=0;i<=k;i++)
     {
       if(count[i]>=2)
       {
           int d=count[i]/2;
           newwt=newwt+Wr+(2*i*d);
           if(newwt>=W)
           {
               o=1;
               break;
           }
           
       }
     }
  
     if(o==1)
     cout<<"YES"<<endl;
     else
      cout<<"NO"<<endl;
      
      T--;
}

}

You are getting WA , because you are missing two things.

  1. If the weight of the rod is greater than or equal to W then answer is Yes.
  2. You have to use long to avoid integer overflow.
    Happy Coding :slightly_smiling_face:

GOT IT!!!
THANKS

1 Like