Sponsors

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;
}

 

Hong Kong-Based IP Management...

Hong Kong's Medialink Group Expands its Reach into Japan Hong...

XRP Bearish Signal: Whales...

XRP Bearish Signal: Whales Offload $486 Million in Asset The...

Faraday Future Founder and...

Faraday Future Spins Off Crypto Venture: CXC10 on the...

Ice Cube Says Critical...

Ice Cube's Shocking Revelation: "War of the Worlds" Remake...

Curtis Jones to Miss...

Curtis Jones Out, But Liverpool Avoid Major Injury Concerns...

Los Angeles County child...

Los Angeles County Child Dies from Measles Complications A tragic...

Hong Kong-Based IP Management Company Medialink Group Expands Into Japan With New Subsidiary Launch (EXCLUSIVE)

Hong Kong's Medialink Group Expands its Reach into Japan Hong Kong-based intellectual property (IP) management company, Medialink Group Limited, has made a significant move into...

XRP Bearish Signal: Whales Offload $486 Million In Asset

XRP Bearish Signal: Whales Offload $486 Million in Asset The cryptocurrency market is known for its volatility, and recent on-chain data suggests a potential bearish...

Faraday Future Founder and Co-CEO YT Jia Shares Weekly Investor Update: FF Officially Started the Spinoff Plan for the Crypto Flywheel, a Second Independently...

Faraday Future Spins Off Crypto Venture: CXC10 on the Horizon Faraday Future, the electric vehicle company, is making waves beyond its automotive ambitions. Founder...

Ice Cube Says Critical Disaster Shot Without Director Or Actors Present

Ice Cube's Shocking Revelation: "War of the Worlds" Remake Filmed Without Crew? The 2025 remake of H.G. Wells's War of the Worlds has been met...

Curtis Jones to Miss Burnley But No Other Post-Internationals Injury Concerns

Curtis Jones Out, But Liverpool Avoid Major Injury Concerns After International Break Liverpool fans can breathe a sigh of relief. While Curtis Jones will...

Los Angeles County child dies from complications caused by measles infection, public health officials say

Los Angeles County Child Dies from Measles Complications A tragic incident in Los Angeles County highlights the severe and potentially fatal consequences of measles infection,...

NASA Says Mars Rover Discovered Potential Biosignature Last Year

NASA's Perseverance Rover Finds Potential Biosignature on Mars In a groundbreaking announcement, NASA has revealed that its Perseverance rover discovered a potential biosignature in a...

Bettors Bet Big On Trump Pardoning Binance Founder Changpeng Zhao

Bettors Bet Big on Trump Pardoning Binance Founder Changpeng Zhao A surprising prediction market trend has emerged, suggesting a significant possibility of a presidential pardon...

6 Best Long-Running Sci-Fi TV Series to Binge-Watch

6 Best Long-Running Sci-Fi TV Series to Binge-Watch Science fiction television has given us some of the most imaginative and enduring stories in recent years....