Submission #872937

#TimeUsernameProblemLanguageResultExecution timeMemory
872937vjudge1Climbers (RMI18_climbers)C++17
5 / 100
1 ms856 KiB
#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 (stderr)

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++){
      |                 ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...