Language: C++

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int returnMinIndex(vector<long long> v, long long a){
    long long index = 0;
    long long min = abs(a-v[0]);
    for(int i=0;i<v.size();i++){
        if(min > abs(a-v[i])){
            min = abs(a-v[i]);
            index =i;
        }
    }
    return index;
}
int returnMin(vector<long long> v, long long a){
    long long index = 0;
    long long min = abs(a-v[0]);
    for(int i=0;i<v.size();i++){
        if(min > abs(a-v[i])){
            min = abs(a-v[i]);
            index =i;
        }
    }
    return min;
}
int returnMaxIndex(vector<long long> v, long long a){
    long long index = 0;
    long long max = abs(a-v[0]);
    for(int i=0;i<v.size();i++){
        if(max < abs(a-v[i])){
            max = abs(a-v[i]);
            index =i;
        }
    }
    return index;
}
int returnMax(vector<long long> v, long long a){
    long long index = 0;
    long long max = abs(a-v[0]);
    for(int i=0;i<v.size();i++){
        if(max < abs(a-v[i])){
            max = abs(a-v[i]);
            index =i;
        }
    }
    return max;
}


int main(){
    int n;
    long long z,w, tmp, ans;
    long long max,min,index;
    vector<long long> v;
    cin >> n >> z >> w;
    for(int i=0;i<n;i++){
        cin >> tmp;
        v.push_back(tmp);
    }
    bool x = true; // true->x, false->y
    for(int i=0; i<n;i++){
        cout << i << endl;
        if(x){
            index = i;
            vector<long long> after(v.begin()+i+1, v.end());
            for(int j=i;j<n;j++){
                if(j==i){
                    index = j;
                    max = abs(v[j]-returnMax(after,v[j]));
                } else {
                    if(max < abs(v[j]-returnMax(after, v[j])){
                        index = j;
                        max = abs(v[j]-returnMax(after, v[j]))
                    }
                }
            }
            x = !x;
            i =index;
        } else {
            index =i;
            vector<long long> after(v.begin()+i+1, v.end());
            for(int j=i;j<n;j++){
                if(j==i){
                    index = j;
                    min = abs(v[j]-returnMin(after,v[j]));
                } else {
                    if(min > abs(v[j]-returnMin(after, v[j])){
                        index = j;
                        min = abs(v[j]-returnMin(after, v[j]))
                    }
                }
            }
            x = !x;
            i =index;
        }
    }
    ans = abs(z-w);
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:74:62: error: expected ')' before '{' token
   74 |                     if(max < abs(v[j]-returnMax(after, v[j])){
      |                       ~                                      ^
      |                                                              )
a.cc:78:17: error: expected primary-expression before '}' token
   78 |                 }
      |                 ^
a.cc:90:62: error: expected ')' before '{' token
   90 |                     if(min > abs(v[j]-returnMin(after, v[j])){
      |                       ~                                      ^
      |                                                              )
a.cc:94:17: error: expected primary-expression before '}' token
   94 |                 }
      |                 ^