CodeFoeces-581B

题目

原题链接:B. Luxurious Houses

题意

有n个房子,现需要给每个房子加高,保证每个房子高于所有它右侧的房子。
参考其他作者思路,从右向左边找最大值比较从而加高即可。

代码

#include
using namespace std;
int main() {
    int n,s[100000];
    scanf("%d",&n);
    for(int i=0; i=0; i--) {
        int tmp=hmax+1-s[i];
        hmax=max(hmax,s[i]);
        s[i]=tmp<0?0:tmp;
    }
    for(int i=0; i

你可能感兴趣的:(CodeFoeces-581B)