CF883K.Road Widening

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy!

The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time on the street.

The street is split into nn equal length parts from left to right, the ii -th part is characterized by two integers: width of road sis_{i} and width of lawn gig_{i} .

For each of nn parts the Mayor should decide the size of lawn to demolish. For the ii -th part he can reduce lawn width by integer xix_{i} ( 0<=xi<=gi0<=x_{i}<=g_{i} ). After it new road width of the ii -th part will be equal to si=si+xis'_{i}=s_{i}+x_{i} and new lawn width will be equal to gi=gixig'_{i}=g_{i}-x_{i} .

On the one hand, the Mayor wants to demolish as much lawn as possible (and replace it with road). On the other hand, he does not want to create a rapid widening or narrowing of the road, which would lead to car accidents. To avoid that, the Mayor decided that width of the road for consecutive parts should differ by at most 11 , i.e. for each ii ( 1<=i<n ) the inequation si+1si<=1|s'_{i+1}-s'_{i}|<=1 should hold. Initially this condition might not be true.

You need to find the the total width of lawns the Mayor will destroy according to his plan.

输入格式

The first line contains integer nn ( 1<=n<=21051<=n<=2·10^{5} ) — number of parts of the street.

Each of the following nn lines contains two integers si,gis_{i},g_{i} ( 1<=si<=1061<=s_{i}<=10^{6} , 0<=gi<=1060<=g_{i}<=10^{6} ) — current width of road and width of the lawn on the ii -th part of the street.

输出格式

In the first line print the total width of lawns which will be removed.

In the second line print nn integers s1,s2,...,sns'_{1},s'_{2},...,s'_{n} ( si<=si<=si+gis_{i}<=s'_{i}<=s_{i}+g_{i} ) — new widths of the road starting from the first part and to the last.

If there is no solution, print the only integer -1 in the first line.

输入输出样例

  • 输入#1

    3
    4 5
    4 5
    4 10
    

    输出#1

    16
    9 9 10 
    
  • 输入#2

    4
    1 100
    100 1
    1 100
    100 1
    

    输出#2

    202
    101 101 101 101 
    
  • 输入#3

    3
    1 1
    100 100
    1 1
    

    输出#3

    -1
    
首页