Advertisement
mickypinata

FORCE-T1352B: Same Parity Summands

Nov 22nd, 2021
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6.     int Q;
  7.     scanf("%d", &Q);
  8.     while(Q--){
  9.         int sum, n;
  10.         scanf("%d%d", &sum, &n);
  11.         if(sum % 2 == n % 2){
  12.             int lst = sum - n + 1;
  13.             if(lst < 0){
  14.                 cout << "NO\n";
  15.                 continue;
  16.             }
  17.             cout << "YES\n";
  18.             for(int i = 1; i < n; ++i){
  19.                 cout << "1 ";
  20.             }
  21.             cout << lst << '\n';
  22.         } else if(sum % 2 == 0){
  23.             int lst = sum - n - n + 2;
  24.             if(lst <= 0){
  25.                 cout << "NO\n";
  26.                 continue;
  27.             }
  28.             cout << "YES\n";
  29.             for(int i = 1; i < n; ++i){
  30.                 cout << "2 ";
  31.             }
  32.             cout << lst << '\n';
  33.         } else {
  34.             cout << "NO\n";
  35.         }
  36.     }
  37.  
  38.     return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement