Poj2355--railway Tickets

Source: Internet
Author: User

Railway Tickets
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2710 Accepted: 962

Description

The railway line "Ekaterinburg-sverdlovsk" with several stations have been built. This railway line can is represented as a line segment, railway stations being points on it. The railway line starts at the station ' Ekaterinburg ' and finishes at the station ' Sverdlovsk ', so stations is numbered s Tarting from "Ekaterinburg" (it had number 1) and "Sverdlovsk" is the last station.

Cost of the ticket between any and stations depends only on a distance between them. The prices for the tickets is specified in the following table.

Distance between stations-X

Price for the ticket

0<X<=L1

C1

L1<X<=L2

C2

L2<X<=L3

C3


Direct tickets from one station to another can is booked if and only if the distance between these station does not exceed L3. So sometimes it was necessary to book several tickets to pay for the parts of the whole by between.

For example, on the railway line shown at the figure above there is seven stations. The direct ticket from the second station to the sixth one can is booked. There is several ways to pay for the travel between these stations. One of them is to book Tickets:one ticket at Price C2 to travel between the second and the third stations, and other At price C3 to travel between the third and the sixth stations. Note, that though the distance between the second and the sixth stations are equal to 2*L2, the whole travel can isn't be pai D by booking-tickets at the price C2, because each ticket was valid for only one travel and all travel should start and EN D only at stations.

Your task is-to-write a program, which would find the minimal cost of the travel between the given stations.

Input

The first line of the input file contains 6 integers L1, L2, L3, C1, C2, C3 (1 <= L1 < L2 < L3 <= 10^9, 1 < = C1 < C2 < C3 <= 10^9) in the specified order with one space between. The second line contains the amount of stations n (2 <= n <= 10000). The third line contains and different integers separated by space. They represent serial numbers of stations, the travel between which must is paid. Next N-1 lines contain distances from the first station ("Ekaterinburg") on the railway line to others. These distances is given as different positive integers and is arranged in the ascending order. The distance from ' Ekaterinburg ' to ' Sverdlovsk ' does not exceed 10^9. The distance between any neighboring stations does not exceed L3. The minimal travel cost between the given stations would not exceed 10^9.

Output

program should print to the output file of the only number, which are the minimal travel cost between the given stations.

Sample Input

3 6 8 20 30 4072 6378131523

Sample Output

70

Source

Ural Collegiate Programming Contest 1999

Water DP, at the beginning of the thought of using line tree to optimize, the result of violence is over

#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring># Include <iostream> #include <algorithm>using namespace std;const int inf = 0x3f3f3f3f;const int N = 10010;int D P[n];int Sta[n];int Main () {int L1, L2, L3;int C1, C2, C3;int N, S, E;while (~scanf ("%d%d%d%d%d%d", &l1, &l2, &l 3, &AMP;C1, &AMP;C2, &c3)) {//printf ("%i64d\n", INF); scanf ("%d", &n); scanf ("%d%d", &s, &e); if (S > E) { Swap (S, e);} Memset (DP, INF, sizeof (DP)), sta[1] = 0;dp[e] = 0;for (int i = 2; I <= n; ++i) {scanf ("%d", &sta[i]);} for (int i = e-1; I >= s; i.) {for (int j = i; J <= E; ++j) {if (Sta[j]-sta[i] > L3) {break;} if (Sta[j]-sta[i] <= L1) {Dp[i] = min (Dp[i], Dp[j] + C1);} else if (Sta[j]-sta[i] <= L2) {Dp[i] = min (Dp[i], dp[j] + C2);} Else{dp[i] = min (Dp[i], Dp[j] + C3);}}} printf ("%d\n", Dp[s]);} return 0;}


Poj2355--railway Tickets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.