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

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

#include<stdio.h>
#include<stdlib.h>
typedef unsigned u;
u D[222222],H[222222],P[222222],A[222222];
int main()
{
	u n,d,x,i=-1,j,k,mi=0,ma=1;
	for(scanf("%u%u%u",&n,&d,&x);++i<d;)scanf("%u",D+i);
	for(i=d;i--;ma+=D[i]-1)if(D[i]>D[i+1])mi+=D[i]-D[i+1];
	if(x<mi||x>ma){printf("-1\n");return 0;}
	for(A[i=0]=2;i++<d;)A[i]=A[i-1]+D[i-1];
	for(i=1;++i<A[1];)P[i]=1;
	for(i=0;++i<d;)
	{
		k=D[i-1]-1;
		if(k>D[i]-1)k=D[i]-1;
		j=ma-x;
		if(j>k)j=k;
		ma-=j;
		j=A[i]-1-j;
		for(k=A[i]-1;++k<A[i+1];)
		{
			P[k]=j;
			if(j+1<A[i])++j;
		}
	}
	for(printf("%u\n",A[d]-1);n>1;--n)printf("%u %u\n",n,P[n]);
	return 0;
}

 

Everything You Need to...

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

Russ Allbery: Review: Radiant...

Science fiction enthusiasts and literary critics alike are turning...

Why Pet Travel Gear...

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

Mall Together-TENOKE

Simulation gaming enthusiasts have a fresh operational challenge to...

7 Reasons This Coffee...

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

Why Kitchen Organization Tools...

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

Everything You Need to Know About Rechargeable Home Tech Right Now

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

Russ Allbery: Review: Radiant Star

Science fiction enthusiasts and literary critics alike are turning their eyes toward the upcoming release of Radiant Star, the latest novel by award-winning author...

Why Pet Travel Gear Is Currently Breaking the Internet

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

Mall Together-TENOKE

Simulation gaming enthusiasts have a fresh operational challenge to tackle with the arrival of Mall Together-TENOKE. This brand-new release delivers an immersive shopping mall...

7 Reasons This Coffee Bar Accessories Is Worth Every Single Penny

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

Why Kitchen Organization Tools Is Currently Breaking the Internet

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

Is Dorm Room Hacks Worth Your Money Here Is Our Full Review

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

Stop Buying Cheap Alternatives This Camping Essentials Is the Real Deal

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

Everything You Need to Know About Outdoor Patio Tech Right Now

📢 As an Amazon Associate, I earn from qualifying purchases.I'll be honest — I was skeptical at first. My daily routine had a gap...