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

I Tried Viral Kitchen...

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

How Viral Kitchen Gadgets...

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

Avengers: Armageddon #5 Preview:...

Tension Reaches a Breaking Point in Avengers: Armageddon #5 Marvel's...

7 Reasons This Viral...

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

Can baby deer walk...

Witnessing a newborn animal take its very first steps...

Is the Anker MagGo...

The Long-Term Durability Assessment: 6 Months as a Daily...

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...

How Viral Kitchen Gadgets Is Quietly Changing the Game

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

Avengers: Armageddon #5 Preview: Trust Issues Intensify

Tension Reaches a Breaking Point in Avengers: Armageddon #5 Marvel's mightiest heroes are once again staring down total catastrophe, but this time, the greatest danger...

7 Reasons This Viral Kitchen Gadgets Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

Can baby deer walk right away?

Witnessing a newborn animal take its very first steps is one of the most heartwarming sights in the natural world. In the wild, however,...

Is the Anker MagGo 3-in-1 Worth $100? Long-Term Durability Review

The Long-Term Durability Assessment: 6 Months as a Daily Driver Spending $100 on a smartphone charging accessory is a significant consumer investment. When budget 3-in-1...

Anker MagGo 3-in-1 vs Belkin BoostCharge Pro 3-in-1: Which Is Better?

The Heavyweight Showdown: Anker MagGo vs. Belkin BoostCharge Pro For the past four years, if an Apple user wanted the absolute best 3-in-1 wireless charging...

Best Protective Travel Pouches and Cases for Anker MagGo 3-in-1

Protecting Your Premium Travel Power Investment The Anker MagGo 3-in-1 Foldable Charging Station is engineered for life on the move. With its collapsible form factor,...

How Fast Does Anker MagGo Charge iPhone 15 and 16 from 0 to 100%?

Putting Qi2 15W Speed Claims to the Test When wireless charging standards make technological leaps, consumer skepticism is natural. For years, marketing promises of "fast...