Codeforces Global Round 7 B. Maximums(逻辑)

题意:

有数组 an,定义 xi 为 a 的前 i - 1 位的最大值(x= 0),定义 bi 为 ai - xi,给出数组 bn,还原数组 an

思路:

因为 x= 0,所以 b0 = a0,之后维护最大值即可。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;cin>>n;
    ll b[n];for(ll &i:b) cin>>i;
    ll a[n],mx=0;
    for(int i=0;i<n;i++){
        a[i]=mx+b[i];
        if(b[i]>0) mx+=b[i];
    }
    for(ll i:a) cout<<i<<' ';
    return 0;
}

 

posted @ 2020-03-20 01:17  Kanoon  阅读(218)  评论(0编辑  收藏  举报