Codeforces Round #386 (Div. 2), problem: (C) Tram Solution in C/C++

Codeforces Round #386 (Div. 2), problem: (C) Tram Solution in C/C++

#include<stdio.h>
typedef unsigned u;
u x1,x2,s;
u F(u p,u d,u k)
{
	if(k==2)return-1;
	if(!p&&d==-1u)return F(p,-d,k);
	if(p==s&&d==1)return F(p,-d,k);
	if(k==1&&p==x2)++k;
	if(k==0&&p==x1)++k;
	return 1+F(p+d,d,k);
}
int main()
{
	u t1,t2,p,d,a,b;
	scanf("%u%u%u%u%u%u%u",&s,&x1,&x2,&t1,&t2,&p,&d);
	a=F(p,d,0)*t1;
	b=(x1>x2?x1-x2:x2-x1)*t2;
	printf("%u\n",a>b?b:a);
	return 0;
}

Advertisement

spot_img

Why Viral Kitchen Gadgets...

📢 As an Amazon Associate, I earn from qualifying...

Curt Cignetti has built...

College football is often dictated by resources, prestige, and...

I Tried Viral Kitchen...

📢 As an Amazon Associate, I earn from qualifying...

Top House Budget Dem...

In response to growing scrutiny over the reliability and...

I Tried Viral Kitchen...

📢 As an Amazon Associate, I earn from qualifying...

‘Feeling good’ – Shams...

Basketball fans can breathe a collective sigh of relief...

Why Viral Kitchen Gadgets Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Curt Cignetti has built what Lincoln Riley can’t at USC: a team that knows how to win

College football is often dictated by resources, prestige, and five-star recruiting classes. Yet, the stark contrast between Curt Cignetti’s Indiana Hoosiers and Lincoln Riley’s...

I Tried Viral Kitchen Gadgets For 30 Days Here Is the Honest Truth

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Top House Budget Dem Boyle: I’d Support ‘Major Appropriation’ for FAA Overhaul

In response to growing scrutiny over the reliability and resilience of national aviation infrastructure, Representative Brendan Boyle (D-PA) has publicly signaled strong support for...

I Tried Viral Kitchen Gadgets For 30 Days Here Is the Honest Truth

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

‘Feeling good’ – Shams Charania provides Luka Doncic, Austin Reaves injury updates

Basketball fans can breathe a collective sigh of relief following the latest Luka Doncic Austin Reaves injury updates delivered by trusted NBA insider Shams...

The Ultimate Viral Kitchen Gadgets Guide You Didnt Know You Needed

📢 As an Amazon Associate, I earn from qualifying purchases.Most products in this category disappoint within weeks. Cheap materials, vague instructions, and results that...

Connor Hellebuyck goes to Bass Pro Shops opening in NJ — one day after brutal Winnipeg booing

Professional sports can be an emotional rollercoaster, and few understand that reality better this week than Winnipeg Jets star goaltender Connor Hellebuyck. Just twenty-four...

Why Viral Kitchen Gadgets Is Currently Breaking the Internet

em> If you had told me six months ago that a single purchase would change how I approach my daily routine, I would not have...