#include<bits/stdc++.h>
using namespace std;
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#define f first
#define s second
typedef long long ll;
ll a[200100];
void solve(){
ll n; cin>>n;
for(ll i=1; i<=n; i++){
cin>>a[i];
}
vector<ll> v;
for(ll i=1; i<=n; i++){
if(v.size() < 2) v.push_back(a[i]);
else if(v[v.size()-1] > v[v.size()-2] && v[v.size()-1] < a[i]){
v.pop_back();
v.push_back(a[i]);
} else if(v[v.size()-1] < v[v.size()-2] && v[v.size()-1] > a[i]){
v.pop_back();
v.push_back(a[i]);
} else{
v.push_back(a[i]);
}
}
ll l=0,r=v.size()-1;
vector<ll> ord;
while(l<=r){
if(v[l] <= v[r]){
ord.push_back(v[l]);
l++;
} else{
ord.push_back(v[r]);
r--;
}
}
ll ans=0;
for(ll i=0; i<ord.size()-1; i++){
ans+=abs(ord[i+1]-ord[i]);
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
for(int i = 1; i <= t; i++){
// cout<<"Case "<<i<<":\n";
solve();
cout<<'\n';
}
}
Compilation message
climbers.cpp: In function 'void solve()':
climbers.cpp:39:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(ll i=0; i<ord.size()-1; i++){
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
464 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
856 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
856 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |