import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

struct Edge {
    int from, to; long cost;
}
void main() {
    int N, M; long X; readf("%s %s %s\n", &N, &M, &X);
    auto H = new long[N];
    foreach (i; 0 .. N) {
        H[i] = readln.chomp.to!long;
    }
    auto G = new Edge[][N];
    foreach (i; 0 .. M) {
        int a, b; long t; readf("%s %s %s\n", &a, &b, &t); a--; b--;
        G[a] ~= Edge(a, b, t);
        G[b] ~= Edge(b, a, t);
    }
    immutable INF = long.max / 4;
    struct P { int v; long cost; }
    BinaryHeap!(Array!P, "a.cost > b.cost") PQ;
    auto D = new long[N]; D[] = INF;
    PQ.insert(P(0, 0));
    D[0] = 0;
    long ans = INF;
    while (! PQ.empty) {
        auto c = PQ.front; PQ.removeFront;
        long cur_height = X - c.cost;
        if (cur_height < 0) cur_height = 0;
        assert(cur_height <= H[c.v]);
        foreach (e; G[c.v]) {
            if (e.cost > H[c.v]) continue; // cannot reach e.to
            long ncost = c.cost + e.cost + max( 0, cur_height - (H[e.to] + e.cost), e.cost - cur_height );
            if (D[e.to] > ncost) {
                D[e.to] = ncost;
                PQ.insert(P(e.to, ncost));
            }
        }
        if (c.v == N - 1) {
            ans = min(ans, c.cost + H[N - 1] - cur_height);
        }
    }
    if (ans >= INF) {
        writeln(-1);
    } else {
        writeln(ans);
    }
}