Codeforces Round #629 (Div. 3) 1328B - K-th Beautiful String Solution



 

Problem  Link :  https://codeforces.com/problemset/problem/1328/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);
    int  t;
    cin >> t;
    while ( t-- )
    {
        int n,k,i;
        cin>>n>>k;
        ll s=0, pos=0;
        for(i = 0 ; ; i++ )
        {
            s+=i;
            if(s>=k)
            {
                pos=i;
                break;
            }
        }
        int  u,v;
        u=n-pos-1;
        v=n-(k-(pos*(pos-1)/2));
        for(i = 0 ; i < n ; i++)
        {
            if(i==u||i==v)
                cout<<"b";
            else
                cout<<"a";
        }
        cout<<endl;
    }
}








No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.