< Back to forum

Chef Feeds Cats

#include <iostream.h>

using namespace std;

int main() { int t ,j; cin>>t; for(j=0 ;j<t ;j++) { int n, m ,q ,r ,parth=1 , khushi=1 ,k ,l ,sum1=0,sum2=0; cin>>n>>m; q=m/n; cout<<q<<" "; if(q!=0) { int p; p=qn; int arr[p]; sum2=(n(n+1))/2;

    
     for(k=0;k<p ;k++)
     {
        arr[k]=0;
     }
     for(k=0;k<q ;k++)
     {
        
        for(l=n*k ;l<n*k+n ;l++)
        {
            cin>>arr[l];
            sum1=sum1+arr[l];
            cout<<sum1<<" ";
        }
        cout<<endl;
        if(sum1!=sum2)
        {
            parth=0;
            break;
        }
       
        sum1=0;
     }
    }
           
    r=m%n;
    if(r!=0)
    {
     int arr2[r],hash[n+1];
     hash[0]=0;
     for(k=1;k<=n;k++)
     {
        hash[k]=0;
     }
     for(k=0;k<r;k++)
     {
        arr2[k]=0;
     }
     for(k=0;k<r;k++)
     {
        cin>>arr2[k];
        hash[arr2[k]]++;
        
     }
     for(k=0;k<r;k++)
     {
         if(hash[arr2[k]]>1)
         {
             khushi=0;
             break;
         }
     }
     }
     if(parth==1 && khushi ==1)
     {
        cout<<"YES"<<" "<<parth<<" "<<khushi<<endl;
     }
     else
     {
        cout<<"NO"<<" "<<parth<<" "<<khushi<<endl;
        parth=1;
        khushi=1;
     }
   
    
    
}

return 0;

}

Asked by: Anonymous on March 31, 2020, 1:10 p.m. Last updated on March 31, 2020, 1:10 p.m.


cout<<sum1; is deleted cout<<parth<<khushi is also deleted

parthvyasvadodara last updated on March 31, 2020, 1:19 p.m.

due to some pre--processing done by markdown language some parts of your code can be missed

for example you written as sum2=(n*(n+1))/2; which is converted as sum2=(n(n+1))/2; in above solution

there may be many things like this so we are unable to find errors properlly

so send a link to your solution and also problem

sharshach last updated on April 2, 2020, 4:22 p.m.

always send a link to problem statment and solution(if there is one).

sharshach last updated on April 2, 2020, 4:23 p.m.

Enter your answer details below:


Preview

Enter your comment details below:

Preview




1 Answer(s)

avatar

any way I am up with a solution to this

solution: click here

to know what errors you have made send your link in comment section

sharshach last updated on April 2, 2020, 4:39 p.m. 0    Reply    Upvote   

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.