#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
 
using namespace std;
const long double eps = 1e-12;
 
typedef long long ll;
typedef pair<int , int> pt;
 
#define sz(a) ((int) a.size() )
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i , a , b) for (int i = a ; i <= b ; i++)
#define Ford(i , a , b) for (int i = a ; i >= b ; i--)
#define Rep(i , n) for (int i = 0 ; i < n ; i++)
 
const int maxn = 100000 + 1912;
int n , m , X;
int h[maxn];
struct edge{
    int u , v , w;
} e[maxn * 6];
vector<int> V[maxn];
 
void ReadData() {
    scanf("%d%d%d" , &n , &m , &X);
    For(i , 1 , n) scanf("%d" , &h[i]);
    For(i , 1 , m) scanf("%d%d%d" , &e[i].u , &e[i].v , &e[i].w);
    For(i , 1 , m) {
        e[i + m] = e[i];
        swap(e[i + m].u , e[i + m].v);
    }
    m <<= 1;
    For(i , 1 , m) {
        V[e[i].u].push_back(i);
    }
}
 
const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000 + 1912;
long long d[maxn];
priority_queue<pair<long long , int> > qu;
bool wasUp[maxn];
 
bool minimize(long long &a , const long long &b) {
    if (a > b) { a = b; return true; } else return false;
}
 
void Dijkstra() {
    For(i , 1 , n) d[i] = INF;
    d[1] = 0;
    qu.push(make_pair(0 , 1));
 
    while (sz(qu)) {
        pair<long long , int> tt = qu.top(); qu.pop();
        int u = tt.second; long long cur = -tt.first;
        if (d[u] != cur) continue;
        if (X - d[u] > 0) { // continue to go Down
            int curH = X - d[u];
            if (u == n) {
                d[u] += h[u] - curH;
                break;
            }
            Rep(i , sz(V[u])) {
                int id = V[u][i] , v = e[id].v , len = e[id].w;
                if (curH - len >= 0 && curH - len <= h[v]) {
                    if (minimize(d[v] , d[u] + len))
                        qu.push(make_pair(-d[v] , v));
                } else
                if (curH - len > h[v]) {
                    if (minimize(d[v] , d[u] + len + curH - len - h[v]))
                        qu.push(make_pair(-d[v] , v));
                } else
                if (curH - len < 0 && len <= h[u] ) { // Go up
                    if (minimize(d[v] , d[u] + len + len - curH))
                        qu.push(make_pair(-d[v] , v));
                }
            }
        } else { // curH == 0
            if (u == n) {
                d[u] += h[u];
                break;
            }
            Rep(i , sz(V[u])) {
                int id = V[u][i] , v = e[id].v , len = e[id].w;
                if (len <= h[u]) {
                    if (minimize(d[v] , d[u] + len * 2))
                        qu.push(make_pair(-d[v] , v));
                }
            }
        }
    }
 
   // For(i , 1 , n) cout << d[i] << " "; cout << endl;
 
    if (d[n] >= INF) { // cant go
        cout << -1 << endl;
    } else {
        cout << d[n] << endl;
    }
}
 
void Process() {
    Dijkstra();
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
    ReadData();
    Process();
}

Measured memory_bytes: 18168