-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathP4552.c
More file actions
27 lines (27 loc) · 749 Bytes
/
P4552.c
File metadata and controls
27 lines (27 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "stdio.h"
#include "stdlib.h"
typedef long long LL;
int main() {
int n;
scanf("%d", &n);
LL d, pre, a;
LL positive = 0, negative = 0;
int i;
for (i = 0; i < n; i++) {
scanf("%lld", &a);
//求差分
//这里d没有使用数组,第i次循环的d表示d[i]
if (i) d = a - pre;
else d = a;
pre = a;
if (i) {
//计算除d[0]外正数之和与负数绝对值之和
d > 0 ? (positive += d) : (negative -= d);
}
}
LL max = positive > negative ? positive : negative;
LL min = positive > negative ? negative : positive;
//最少max次操作,max - min次单独增加/减少操作,d[0]有max - min + 1种不同的值
printf("%lld\n%lld", max, max - min + 1);
return 0;
}