QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 128 MB Total points: 100

#14339. Skiing and Time Capsules

Statistics

a180285 loves skiing. He arrives at a snowy mountain where there are $M$ ski tracks and $N$ intersections between tracks (which are also points of interest). Each point is assigned an index $i$ ($1 \le i \le N$) and an altitude $H_i$. a180285 can ski from point $i$ to point $j$ if and only if there is an edge between $i$ and $j$, and the altitude of $i$ is not less than the altitude of $j$.

Unlike other ski enthusiasts, a180285 likes to visit as many points as possible using the shortest total skiing distance. If he only visits points along a single path, he feels the number of points is too small. Therefore, a180285 takes out his portable time capsules. This is a magical medicine that, once consumed, allows him to immediately return to a previously visited point (without moving and without adding to the distance a180285 has skied). Please note that this magical medicine can be consumed consecutively, meaning he can return to points visited much earlier (such as the point visited before the last one, or even earlier).

Now, a180285 is standing at point 1, looking at the target at the bottom of the mountain, feeling excited. He wants to know, without considering the consumption of the time capsules, the strategy to visit the maximum number of points with the shortest total skiing distance (i.e., minimizing the total skiing distance while satisfying the condition of visiting the maximum number of points). Can you help him find the maximum number of points and the minimum total distance?

Input

The first line contains two integers $N$ and $M$.

The next line contains $N$ integers $H_i$, representing the altitude of each point.

The next $M$ lines describe the distribution of tracks between points. Each line contains three integers $U_i$, $V_i$, and $K_i$, representing a track of length $K_i$ between point $U_i$ and point $V_i$.

Output

Output a single line containing two integers: the maximum number of points a180285 can reach, and the minimum total skiing distance to reach them.

Constraints

For 30% of the data, $1 \le N \le 2000$.

For 100% of the data, $1 \le N \le 100000$.

For all data, $1 \le M \le 1000000$, $1 \le H_i \le 1000000000$, $1 \le K_i \le 1000000000$.

Examples

Input 1

3 3
3 2 1
1 2 1
2 3 1
1 3 10

Output 1

3 2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.