/*
Jackson Simoneau
SI@UCF 2026 - Intro to Competitive Programming

Solution to https://open.kattis.com/problems/bigtruck
*/

#include <bits/stdc++.h>
using namespace std;

//Represents an item in the queue
//u = a node, dist = distance from node 0, val = number of items picked up
struct qitem {
    int u, dist, val;
};

//Defines the comparison between two qitems to sort them appropriately in the queue
struct Compare {
    bool operator()(const qitem &a, const qitem &b) const {
        //Sort by shorter distance, then by larger number of items
        if(a.dist < b.dist) return true;
        if(a.dist > b.dist) return false;
        return a.val > b.val;
    }
};

int main() {
    int n; cin >> n;
    vector<int> items(n);
    for(int i = 0; i < n; i++) cin >> items[i];

    //Read the weighted edges into an adjacency list
    vector<vector<pair<int, int>>> adj(n);
    int m; cin >> m;
    for(int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }

    //Shortest distance and maximum number of items for each node
    vector<pair<int, int>> dist(n, {100000000, 0});
    dist[0] = {0, items[0]};

    //Define a custom priority queue to sort using the qitem struct
    priority_queue<qitem, vector<qitem>, Compare> q;
    q.push({0, 0, items[0]});

    while(!q.empty()) {
        int u = q.top().u; q.pop();
        //Go through each edge from node u
        for(auto v : adj[u]) {
            //Compute the new distance and number of items for the next node
            pair<int, int> cand = {dist[u].first + v.second, dist[u].second + items[v.first]};
            //Check if this is a shorter distance, or equal distance with more items
            if((cand.first < dist[v.first].first) || (cand.first == dist[v.first].first && cand.second > dist[v.first].second)) {
                //Update the stored values for the next node and insert it into the queue
                dist[v.first] = {cand.first, cand.second};
                q.push({v.first, dist[v.first].first, dist[v.first].second});
            }
        }
    }

    //If we never reached the last node, output impossible
    if(dist[n-1].first == 100000000) cout << "impossible\n";
    //Otherwise, output the shortest distance with the maximum number of items
    else cout << dist[n-1].first << ' ' << dist[n-1].second << '\n';
}