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

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.