Educational Codeforces Round 125 (Rated for Div. 2) 1657BB. XY Sequence Solution




 Problem Link:   https://codeforces.com/contest/1657/problem/B

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long  nn,bb,xx,yy,m,m1,v,i,j,k;
    cin>>v;
    for(k=1; k<=v; k++)
    {
        cin>>nn>>bb>>xx>>yy;
        m=m1=0;
        vector<long long>vec;
        for(j=1; j<=nn; j++)
        {
            if(m+xx<=bb)
            {
                m+=xx;
                  vec.push_back(m);
            }
            else
            {
                m-=yy;
                vec.push_back(m);
            }
        }
        for(i=0;i<vec.size();i++)
            m1+=vec[i];

        cout<<m1<<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 &g...

Powered by Blogger.