ACM Hong Kong online game F question. Crazy Driver (water problem)

Source: Internet
Author: User
Tags time 0

Original title URL: Https://open.kattis.com/problems/driver

Crazy Driver

In the Linear city, there is N gates arranged in a straight line. The gates is labelled from 1 to N. Between adjacent gates, there is a bidirectional road. Each of the road takes one hour to travel and have a toll fee. Since the roads is narrow, you can only travel from gates to gates but cannot U-turn between gates.

Crazy driver Gary starts at Gate 1 at time 0 and he wants to drive through Gate N while minimizing the cost of TR Avelling. However, Gate I only allows a car to pass through after a certain time TI. As Gary is crazy, his car would always be traveling on any one of the roads, i.e., it'll not stop at a gate. What's the minimum cost of him to drive through Gate N ?

As an example, consider the sample input below. An optimal solution is the following:

    • Gate 1 to Gate 2 (cost 5)
    • Gate 2 to Gate 1 (cost 5)
    • Gate 1 to Gate 2 to Gate 3 (cost 9)
    • Go between Gate 3 and gate 4 until 7-th hour (cost 6)
    • Go to and pass through Gate 5 (cost 8)

Input

The first line contains an integer, n(2≤n≤105), the number of gates. The second line has N−1 integers, c1,...,cN−1. C i (1≤Ci≤106) represents the toll fee of the road between gate I and gate i+1. The third line has n integers, t1,...,tn. T i (0≤Ti≤106) represents the opening time (in hour) for each gate. T1 'll always be 0.

Output

Output An integer representing the minimum cost of traveling.

Sample Input 1

Sample Output 1

5

5 4 2 8

0 2 4) 4 8

33

Test instructions: N Gate number 1~n, from the door I to i+1 there is a two-way path, each road spends time is 1 hours, each road flower toll is CI, each door open moment is Ti, a driver from door 1 open to door N, the middle does not stop, That is, if the door does not open when you arrive at door I must travel to the front of the road until the door open, ask the door n at least how much money tolls.

Record the minimum tolls for the road before each door.

#include <algorithm>#include<cstring>#include<string.h>#include<iostream>#include<list>#include<map>#include<Set>#include<stack>#include<string>#include<utility>#include<vector>#include<cstdio>#include<cmath>#defineLL Long Long#defineN 100005#defineINF 0X3FFFFFFusing namespacestd;intN;intC[n];//the travel expenses of door i-1 to gate I are CIintM[n];//minimum tolls for road before gate IintT[n];//every time the door opensintMain () {scanf ("%d",&N);  for(intI=1; i<=n-1; i++) {scanf ("%d",&C[i]); if(i==1) m[i]=C[i]; ElseM[i]=min (m[i-1],c[i]); }       for(intI=0; i<n;i++) {scanf ("%d",&T[i]); }    inttt=0;//Current Moment    intI=0; Long Longret=0;  while(i<N) {i++; TT++; RET+=(Long Long) (C[i]); intTmp=t[i]-tt;//how long till the door is open?             while(tmp>0) {tmp-=2; RET+=(Long Long) (m[i]*2); TT+=2; }} cout<<ret<<Endl; return 0;}

ACM Hong Kong online game F question. Crazy Driver (water problem)

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.