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
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t,n,i,k;
- cin>>t;
- while(t--)
- {
- cin>>n>>k;
- if(n<k)
- cout<<"NO"<<endl;
- else if(k==1)
- {
- cout<<"YES"<<endl;
- cout<<n<<endl;
- }
- else if(n%2==0)
- {
- if(k*2<=n)
- {
- cout<<"YES"<<endl;
- for(i=0; i<k-1; i++)
- {
- cout<<"2 ";
- }
- cout<<n-((k-1)*2)<<endl;
- }
- else if(k%2==0)
- {
- cout<<"YES"<<endl;
- for(i=0; i<k-1; i++)
- {
- cout<<"1 ";
- }
- cout<<n-(k-1)<<endl;
- }
- else
- cout<<"NO"<<endl;
- }
- else
- {
- if(k%2==1)
- {
- cout<<"YES"<<endl;
- for(i=0; i<k-1; i++)
- {
- cout<<"1 ";
- }
- cout<<n-(k-1)<<endl;
- }
- else
- cout<<"NO"<<endl;
- }
- }
- }
No comments