Submission #1119899

#TimeUsernameProblemLanguageResultExecution timeMemory
1119899somefolkClimbers (RMI18_climbers)C++14
0 / 100
2 ms592 KiB
#include <iostream> #include <cmath> #include <algorithm> #include <string> #include <vector> #include <map> #include <unordered_map> #include <queue> #include <set> #include <unordered_set> #include <complex> #include <list> #include <chrono> #include <random> #include <stack> #include <iomanip> #include <fstream> #include <cassert> using namespace std; #define endl "\n" // #define int long long const int INF = 2 * 1e5 + 5; const int MOD = 1e9 + 7; void solve(){ int n; cin >> n; vector<int> in(n); for(int i = 0; i < n; i++){ cin >> in[i]; } // remove increasing or decreasing sequences vector<int> a; bool turn = 0; for(int i = 0; i < n; i++){ if(!turn && in[i] > in[i+1]){ a.push_back(in[i]); turn = 1; } else if(turn && in[i] < in[i+1]) { a.push_back(in[i]); turn = 0; } } // for(auto &i : a) cout << i << " "; int l = 0, r = n-1, sol = a[l]; while(l < r){ if(a[l] <= a[r]){ while(a[l] <= a[r] && l < r){ // cout << "1: " << l << " " << r << "| " << sol << endl; sol += abs(a[l+1] - a[l]); l++; } } else { while(a[r] <= a[l] && l < r){ // cout << "2: " << l << " " << r << "| " << sol << endl; r--; } } } cout << sol << endl; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...