Codeforces 1364A. XXXXX Solution

  Solution in C++:    

///La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///

///Abul Hasnat  Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. int main()
    4. {
    5. int t;
    6. cin>>t;
    7. while(t--)
    8. {
    9. int n,i,sum=0,m1=-1,m2,x,a;
    10. cin>>n>>x;
    11. for(i=0; i<n; i++)
    12. {
    13. cin>>a;
    14. sum+=a;
    15. if(a%x)
    16. {
    17. if(m1==-1)
    18. m1=i;
    19. else
    20. m2=i;
    21. }
    22. }
    23.  
    24. if(sum%x)
    25. cout<<n<<endl;
    26. else if(m1==-1)
    27. cout<<"-1"<<endl;
    28. else
    29.  
    30. cout<<n-min(m1+1,n-m2)<<endl;
    31. }
    32. }
    33.  

    No comments

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

    Powered by Blogger.