Codeforces 1352B. Same Parity Summands 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.  
    6. int t,n,i,k;
    7. cin>>t;
    8. while(t--)
    9. {
    10. cin>>n>>k;
    11. if(n<k)
    12. cout<<"NO"<<endl;
    13. else if(k==1)
    14. {
    15. cout<<"YES"<<endl;
    16. cout<<n<<endl;
    17. }
    18. else if(n%2==0)
    19. {
    20. if(k*2<=n)
    21. {
    22. cout<<"YES"<<endl;
    23. for(i=0; i<k-1; i++)
    24. {
    25. cout<<"2 ";
    26. }
    27. cout<<n-((k-1)*2)<<endl;
    28. }
    29. else if(k%2==0)
    30. {
    31. cout<<"YES"<<endl;
    32. for(i=0; i<k-1; i++)
    33. {
    34. cout<<"1 ";
    35. }
    36. cout<<n-(k-1)<<endl;
    37. }
    38. else
    39. cout<<"NO"<<endl;
    40. }
    41. else
    42. {
    43. if(k%2==1)
    44. {
    45. cout<<"YES"<<endl;
    46. for(i=0; i<k-1; i++)
    47. {
    48. cout<<"1 ";
    49. }
    50. cout<<n-(k-1)<<endl;
    51. }
    52. else
    53. cout<<"NO"<<endl;
    54.  
    55. }
    56.  
    57. }
    58. }
    59.  

    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 ...

    Powered by Blogger.