Codeforces Global Round 7 B - Maximums (thinking title)

Meaning of the questions:

An array of a n- , defined X I  is a front i - 1 bit maximum value (X = 0), is defined B I as a I - X I , to give the array B n- , reducing the array a n- .

Ideas:

Since X = 0, so the B 0 = A 0, after the maintenance to the maximum.

#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]={b[0]};
    ll mx=b[0];
    for(int i=1;i<n;i++){
        a[i]=mx+b[i];
        if(b[i]>0) mx+=b[i];
    }
    for(int i:a) cout<<i<<' ';
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Kanoon/p/12528923.html