bitmasks constructive algorithms math

Please click on ads to support us..

Python Code:

t = int(input())
ans =[]
for _ in range(t):
	n,m = tuple(map(int, input().split()))
	if m>=n:
		if n%2==1:
			s = '1 '*(n-1)
			s+=str(m-(n-1))
			ans.append("Yes\n"+s)
		elif n%2==0 and m%2==0:
			s = '1 '*(n-2)
			s+= str((m-(n-2))//2) + ' ' + str((m-(n-2))//2)
			ans.append("Yes\n"+s)
		else:
			ans.append("No")
	else:
		ans.append("No")
 
 
 
for i in ans:
	print(i)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
int mod = 1e9+7;
const int INF = 4e18;
// int INF = 1e9;
void print(int x){
    cout << x << "\n";
}
void print(int x, int y){
    cout << x << ' ' << y << "\n";
}
void print(int x, int y, int z){
    cout << x << ' ' << y << ' ' << z << "\n";
}
void print(vector<int> x){
    for (auto val: x) cout << val << ' ';
    cout << endl;
}
void print(array<int, 2> x){
    cout << x[0] << ' ' << x[1] << endl;
}
void print(vector<vector<int>> x){
    for (auto val: x) print(val);
    
}
void print(vector<array<int, 2>> x){
    for (auto [a, b]: x) cout << a << ' ' << b << endl;
 
}
void print(set<int> x){
    for (auto val: x) cout << val << ' ';
    cout << endl;
}
void print(multiset<int> x){
    for (auto val: x) cout << val << ' ';
    cout << endl;
}
void print(map<int, int> &x){
    for (auto &[a, b]: x) cout << a << ' ' << b << endl;
}
int log2_floor(int i) {
    return i ? __builtin_clzll(1) - __builtin_clzll(i) : -1;
}
int inv(int a, int b){
    return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int inv(int a){
    return inv(a, mod);
}
vector<int> fact;
vector<int> ifact;
int bin(int N, int K){ 
    if (K>N) return 0;
    if (K<0) return 0;
    if (N<0) return 0;
    int res = 1;
    res *= fact[N]; res %= mod;
    res *= ifact[K]; res %= mod;
    res *= ifact[N-K]; res %= mod;
    return res;
}
void inv_init(int C = 1e6){
    fact.resize(C+1); fact[0] = 1;
    ifact.resize(C+1);
    for (int i=1; i<=C; i++) fact[i] = (i*fact[i-1])%mod;
    ifact[C] = inv(fact[C]);
    for (int i=C-1; i>=0; i--) ifact[i] = ((i+1)*ifact[i+1])%mod;
}
int binpow(int a, int b) {
    a %= mod;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}   
void solve() {
    int n, m; cin >> n >> m;
    if (m<n){
        cout << "NO\n";return;
    }
    if (m%2==1 && n%2==0){
        cout << "NO\n";return;
    }
    cout << "YES\n";
    if (n==1){
        cout << m << "\n";return;
    }
    if (m%2==0){
        for (int i=0; i<n-2; i++){
            cout << 1 << ' ';
        }
        if (n%2==0){
            cout << (m-(n-2))/2 << ' ' << (m-(n-2))/2 << "\n";
        }
        else{
            cout << 1 << ' ' << (m-(n-1)) << "\n";
        }
    }
    else{
        for (int i=0; i<n-2; i++){
            cout << 1 << ' ';
        }        
        cout << 1 << ' ' << (m-(n-1)) << "\n";
    }

}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    // inv_init();
    int tt; cin >> tt;
    for (int xx=1; xx<=tt; xx++)
    solve();
    
}


Comments

Submit
0 Comments
More Questions

688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It
1335B - Construct the String
1004B - Sonya and Exhibition
1397A - Juggling Letters
985C - Liebig's Barrels
115A - Party
746B - Decoding
1424G - Years
1663A - Who Tested
1073B - Vasya and Books
195B - After Training
455A - Boredom
1099A - Snowball
1651D - Nearest Excluded Points
599A - Patrick and Shopping
237A - Free Cash
1615B - And It's Non-Zero
1619E - MEX and Increments
34B - Sale
1436A - Reorder
1363C - Game On Leaves
1373C - Pluses and Minuses
1173B - Nauuo and Chess
318B - Strings of Power
1625A - Ancient Civilization