Submission #872904

#TimeUsernameProblemLanguageResultExecution timeMemory
872904vjudge1Climbers (RMI18_climbers)C++17
0 / 100
1 ms2648 KiB
#include <bits/stdc++.h>
#define f first
#define S second
#define pb push_back
#define msk(x , y) ((x >> y) & 1)
#define all(x) x.begin() , x.end()
using namespace std;
typedef long long int ll;
const int N = 2e5 + 7;
const int mod = 1e9 + 7;
const int dx[] = {-1,-1,1,1,2,-2,2,-2};
const int dy[] = {-2,2,2,-2,1,1,-1,-1};

ll n , a[N] , p[N] , s[N];

void solve(){
	cin >> n ;
	ll ans = 1e18 , pos = 0 , mx = 0 ;
	for(int i = 1 ; i <= n; i++){
		cin >> a[i];
		if(mx < a[i]) mx = a[i] , pos = i ;
	}
	for(int i = 1 ; i <= n ; i++){
		p[i] = p[i - 1] + abs(a[i] - a[i - 1]);
	}
	for(int i = n ; i >= 1 ; i--){
		s[i] = s[i + 1] + abs(a[i] - a[i + 1]);
	}
	cout << max(p[pos] , s[pos]) << "\n";
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);  
    cout.tie(0);
    int test=1;
    // cin >> test ;
    for(int i=1;i<=test;i++){
//      cout << "Case " << i << ": ";
        solve();
     }
}

Compilation message (stderr)

climbers.cpp: In function 'void solve()':
climbers.cpp:18:5: warning: unused variable 'ans' [-Wunused-variable]
   18 |  ll ans = 1e18 , pos = 0 , mx = 0 ;
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...