Submission #261703

#TimeUsernameProblemLanguageResultExecution timeMemory
261703dantoh000Climbers (RMI18_climbers)C++14
5 / 100
2 ms384 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[5005];
int main(){
    scanf("%d",&n);
    for (int i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }
    int l = 1, r = n-2;
    int pos = 0;
    ll ans = 0;
    while (l < r){
        //printf("%d %d\n",l,r);
        if (a[l] < a[r]){
            ans += abs(pos-a[l]);
            pos = a[l];
            l++;
        }
        else{
            ans += abs(pos-a[r]);
            pos = a[r];
            r--;
        }
    }
    ans += abs(pos-a[l]);
    printf("%lld",ans);
}

Compilation message (stderr)

climbers.cpp: In function 'int main()':
climbers.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
climbers.cpp:9:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...