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

来源:互联网 发布:巨人名录数据库网站 编辑:程序博客网 时间:2024/05/01 06:28

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

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define LL long longint 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;}


1 0
原创粉丝点击