#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int a, b, tmp, ans = 0;
scanf("%d", &tmp);
for (int i = 1; i < n; i++)
{
int a;
scanf("%d", &a);
if (a > tmp)ans += a;
tmp = a;
}
printf("%d", ans);
getchar();
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int a, b, tmp, ans = 0;
scanf("%d", &tmp);
for (int i = 1; i < n; i++)
{
int a;
scanf("%d", &a);
if (a > tmp)ans += a;
tmp = a;
}
printf("%d", ans);
getchar();
getchar();
return 0;
}