CF13C.Sequence
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:64MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Petya likes to play very much. And most of all he likes to play the following game:
He is given a sequence of N integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with the smallest number of steps. Petya is not good at math, so he asks for your help.
The sequence a is called non-decreasing if _a_1 ≤ _a_2 ≤ ... ≤ a__N holds, where N is the length of the sequence.
小Petya非常喜欢玩游戏。他最喜欢玩下面这个游戏:
给定一个长度为 N 的整数序列。在每一步中,允许将任意一个数的值加 1 或减 1。游戏的目标是以最少的操作步数,使该序列变为非递减序列。Petya 不擅长数学,因此他向你求助。
若对长度为 N 的序列 a 满足 a1 ≤ a2 ≤ … ≤ aN,则称其为非递减序列。
输入格式
The first line of the input contains single integer N (1 ≤ N ≤ 5000) — the length of the initial sequence. The following N lines contain one integer each — elements of the sequence. These numbers do not exceed 109 by absolute value.
输入的第一行包含一个整数 N(1≤N≤5000)—— 表示初始序列的长度。接下来的 N 行每行包含一个整数 —— 即序列的元素。这些数的绝对值不超过 109。
输出格式
Output one integer — minimum number of steps required to achieve the goal.
输出一个整数——达成目标所需的最少步数。
输入输出样例
输入#1
5 3 2 -1 2 11
输出#1
4
输入#2
5 2 1 1 1 1
输出#2
1
输入解题思路,AI测评打分。不知道怎么写?