#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
const ll maxn = 1e5 + 1, maxm = 1e6 + 1;
const ll mod = 1e9 + 7, inf = 1e9, block = 550, hb = 31, base = 1000050017, biginf = 5e18;
const ld eps = 1e-9;
int n;
int a[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i){
cin >> a[i];
}
ll ans = 0;
int l = 2, r = n - 1;
ans += min(a[l], a[r]);
while (l != r){
if (a[l] < a[r]){
while (l + 1 <= r && a[l + 1] <= a[r]){
ans += abs(a[l] - a[l + 1]);
l += 1;
}
}
else{
while (r - 1 >= l && a[r - 1] <= a[l]){
ans += abs(a[r] - a[r - 1]);
r -= 1;
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
212 KB |
Time limit exceeded |
2 |
Execution timed out |
1089 ms |
212 KB |
Time limit exceeded |
3 |
Execution timed out |
1089 ms |
332 KB |
Time limit exceeded |
4 |
Execution timed out |
1087 ms |
340 KB |
Time limit exceeded |
5 |
Execution timed out |
1092 ms |
340 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1038 ms |
212 KB |
Time limit exceeded |
2 |
Execution timed out |
1087 ms |
212 KB |
Time limit exceeded |
3 |
Execution timed out |
1044 ms |
212 KB |
Time limit exceeded |
4 |
Execution timed out |
1093 ms |
212 KB |
Time limit exceeded |
5 |
Execution timed out |
1078 ms |
212 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1085 ms |
212 KB |
Time limit exceeded |
2 |
Execution timed out |
1081 ms |
212 KB |
Time limit exceeded |
3 |
Execution timed out |
1090 ms |
212 KB |
Time limit exceeded |
4 |
Execution timed out |
1075 ms |
340 KB |
Time limit exceeded |
5 |
Execution timed out |
1082 ms |
340 KB |
Time limit exceeded |
6 |
Execution timed out |
1084 ms |
340 KB |
Time limit exceeded |
7 |
Execution timed out |
1083 ms |
340 KB |
Time limit exceeded |
8 |
Execution timed out |
1075 ms |
340 KB |
Time limit exceeded |
9 |
Execution timed out |
1082 ms |
368 KB |
Time limit exceeded |
10 |
Execution timed out |
1080 ms |
340 KB |
Time limit exceeded |