2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

K

好久前做的,忘记题目了。。。应该是个水题 -_-

#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\n");
        ans += dp[i]-s[i];
    }
    printf("%lld\n", ans);
    rep(i,1,n)
        printf("%d ", dp[i]);

    return 0;
}
posted @ 2017-12-27 15:03  v9fly  阅读(163)  评论(0编辑  收藏  举报