Codeforces Round #331 (Div. 2) B. Wilbur and Array

题意:要求一个a数组经过最少多少次可以变成b数组。a数组的初始值全为0,每次改变可以从i到n改变;

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL long long
int main()
{
    LL n;
    while(scanf("%lld",&n)!=EOF)
    {
        LL a;
        LL temp=0;
        LL sum=0;
        for(LL i=0;i<n;i++)
        {
            scanf("%lld",&a);
            if(a>temp)
            {
                sum+=(a-temp);
            }
            else
            {
                sum+=(temp-a);
            }
            temp=a;
        }
        printf("%lld\n",sum);
    }
    return 0;
}


你可能感兴趣的:(Codeforces Round #331 (Div. 2) B. Wilbur and Array)