【Henu ACM Round#19 B】 Luxurious Houses

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

从右往左维护最大值。 看到比最大值小(或等于)的话。就递增到比最大值大1就好。

【代码】

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5;

int a[N+10],n;

int main()
{
    cin >> n;
    for(int i = 1;i <= n;i++) cin >> a[i];
    int now=0;
    for (int i = n;i >= 1;i--){
        int t = a[i];
        if (a[i]<=now){
                a[i] = now-a[i]+1;

        }else a[i] = 0;

        if (i==n)
                now = t;
        else
                now = max(now,t);
    }
    for (int i = 1;i <= n;i++) cout<<a[i]<<' ';
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/8398211.html