好久前做的,忘记题目了。。。应该是个水题 -_-
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i) #define mes(a,b) memset(a,b,sizeof(a)) #define INF 0x3f3f3f3f #define MP make_pair #define PB push_back #define fi first #define se second typedef long long ll; const int N = 200005; int n, s[N], g[N], dp[N]; int main() { scanf("%d", &n); rep(i,1,n) { scanf("%d%d", &s[i], &g[i]); dp[i] = s[i]+g[i]; } ll ans=0; rep(i,2,n) dp[i] = min(dp[i], dp[i-1]+1); per(i,n-1,1) dp[i] = min(dp[i], dp[i+1]+1); rep(i,1,n) { if(dp[i] < s[i]) return 0*printf("-1 "); ans += dp[i]-s[i]; } printf("%lld ", ans); rep(i,1,n) printf("%d ", dp[i]); return 0; }