#include #define int long long using namespace std; int c, t, n, m, w, sum; int a[200005]; int dis[200005], vis[200005]; struct node{ int v, w; }; struct node2{ int u; bool operator < (node2 b) const{ return dis[this->u] > dis[b.u]; } }; vector G[200005]; priority_queue q; int SPFA(int s, int t){ memset(dis, 0x3f, sizeof dis); memset(vis, 0, sizeof vis); dis[s] = 0; q.push({s}); while (!q.empty()){ node2 tmp = q.top(); q.pop(); int u = tmp.u; if (vis[u]) continue; vis[u] = 1; for (node v : G[u]) if (dis[u] + v.w < dis[v.v]){ dis[v.v] = dis[u] + v.w; q.push({v.v}); } } return dis[t]; } signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin >> n >> m >> c; sum = 0; for (int i = 1; i <= n; i++){ G[i].clear(); cin >> a[i]; sum += a[i]; } G[n + 1].clear(); for (int i = 1; i <= n; i++){ G[i].push_back({i + 1, a[i]}); G[i + 1].push_back({i, a[i]}); } for (int i = 1; i <= m; i++){ int l, r; cin >> l >> r; G[l].push_back({r + 1, c}); G[r + 1].push_back({l, c}); } cout << sum - SPFA(1, n + 1); return 0; }