Codeforces Round #816 (Div. 2) 1715B. Beautiful Array Solution
Problem Link: https://codeforces.com/contest/1715/problem/B
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,t,i,j,f;
cin>>t;
while(t--)
{
ll n,k,b,s,u,a,r;
cin>>n>>k>>b>>s;
if(b*k>s)
{
cout<<"-1"<<endl;
continue;
}
vector<ll>v(n+1,0);
r=b*k;
v[1]=r;
ll d=s-r;
for(i=1; i<=n; i++)
{
a=min(k-1,d);
v[i]+=a;
d-=a;
}
if(d!=0)
{
cout<<"-1"<<endl;
continue;
}
for(i=1; i<=n; i++)
{
cout<<v[i]<<" ";
}
cout<<endl;
}
}
No comments