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