/*
IftekharMd.Shishir
Dept. of Information and Communication Engineering
University of Rajshahi
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define f(i,n) for(i=0;i<n;i++)
#define F(i,n) for(i=n-1;i>=0;i--)
#define fa(i,a,b) for(i=a;i<=b;i++)
#define Fa(i,a,b) for(i=a;i>=b;i--)
#define printArray(i,a,n) f(i,n)cout<<a[i]<<" "; cout<<endl;
#define printLinkedList() temp=head;while(temp){cout<<temp->data<<" ";temp=temp->post;} cout<<endl;
#define pb(x) push_back(x)
#define pob() pop_back()
#define all(a) a.begin(),a.end()
#define sor(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define mem(a,x) memset(a,x,sizeof(a))
#define maxElement max_element
#define minElement min_element
//[ ll *it; it = maxElement(a,a+n); ]
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define txtIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define txtTest freopen("C:/Users/Iftekhar/Documents/what/input.txt", "r", stdin);
#define FastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
#define TestCase ll t;cin>>t;while(t--)
#define points(x) fixed<<setprecision(x)
#define gcd(x,y) __gcd(x,y)
#define scd(a,x,y) a/gcd(x,y);
#define nl cout<<endl;
#define done return 0
const double PI= 2*acos(0.0);
const long long MOD= 1000000007;
const long long MAX = 32000;
// stringstream demo(str); demo >> x;
// stringstream demo; demo << x; name=demo.str();
using namespace std;
int main()
{
FastIO;
//txtTest;
ll v1,v2,t,k,mi,mx,ans=0,temp=0,flag=0,cnt=0,p=0;
cin >> v1 >> v2 >> t >> k;
t-=2;
mi = min(v1,v2);
mx = max(v1,v2);
ans += mx+mi;
temp = mx;
while (t--)
{
if((t+1)*k>=temp+k-mi && !flag)
{
temp+=k;
ans+=temp;
}
else if((t+1)*k<temp+k-mi && !flag)
{
flag=1;
}
if(flag)
{
ll x=mi;
while (1)
{
if(x+k<temp) {
x+=k;
ans+=x;
cnt++;
if(x+k>=temp) p+=((x+k)-p);
}
else break;
}
x= t+1-cnt;
while (x>0)
{
ans+=p;
x--;
}
cout << ans <<endl;
done;
}
}
cout<< ans<<endl;
done;
}
Comments
Post a Comment