Sightseeing bus (Codevs 1139)

Source: Internet
Author: User

Title Description Description

The charming town of Y city has n beautiful sights. Due to the increasing number of tourists, Y city has specially arranged a sightseeing bus to provide more convenient transportation services for tourists. The sightseeing bus appears at attraction No. 1th in 0 minutes and then goes to attractions 2, 3 and 4......N. It takes a di minute to get to the sights of i+1 from the attractions of No. i. At any moment, the bus can only go forward or wait at the sights.
With a total of M visitors, each traveler needs to travel 1 times from one attraction to another, and the first visitor in Ti minutes comes to attractions Ai, wishing to travel to attractions Bi (AI<BI). In order for all passengers to arrive at their destination smoothly, the bus must wait for all passengers who need to depart from the attraction at each station before leaving for the next attraction.
Let's say passengers don't need time to hop on and off.
The travel time of a passenger is equal to the moment he arrives at the destination minus the moment he arrives at the departure point. Because there is only one sightseeing car, and sometimes stop waiting for other passengers, passengers complain that travel time is too long. So the clever driver ZZ installed K Nitrogen Accelerator for the bus, each using an accelerator, can make one di minus 1. The accelerator can be reused for the same di, but it must be guaranteed that the DI is greater than or equal to 0.

So how does ZZ plan to use the accelerator to minimize the total travel time for all passengers?

Enter a description Input Description

The 1th line is 3 integers n, m, K, separated by a space between every two integers. The number of attractions, passengers and nitrogen accelerator are indicated respectively.
Line 2nd is a n-1 integer, separated by a space between each of the two integers, and the number of numbers indicates the time required to travel from the first I attraction to the i+1, i.e. di.
Line 3rd to m+2 3 integers per line ti, Ai, Bi, each of the two integers separated by a space. Line i+2 Indicates the moment when the first passenger arrives at the departure point, the number of the departure attraction and the number of the arriving attraction.

Output description Output Description

A total of one row, containing an integer that represents the minimum total travel time.

Sample input Sample Input

3 3 2
1 4
0 1 3
1 1 2
5 2 3

Sample output Sample Output

10

Data range and Tips Data Size & Hint

Use 2 accelerators for D2, from attractions 2nd to 3rd, to 2 minutes.
The bus departs from 1th attractions in the 1th minute, 2 minutes to the 2nd attractions, and the 5th minute from the 2nd attractions, and 7 minutes to the 3rd attractions.
1th Traveller travel Time 7-0 = 7 minutes.
2nd Traveller travel Time 2-1 = 1 minutes.
3rd Traveller travel Time 7-5 = 2 minutes.
Total time 7+1+2 = 10 minutes.


Data range
For 10% of data, k=0;
For 20% of data, k=1;
For 40% of data, 2≤n≤50,1≤m≤1,000,0≤k≤20,0≤di≤10,0≤ti≤500;
For 60% of data, 1≤n≤100,1≤m≤1,000,0≤k≤100,0≤di≤100,0≤ti≤10,000;
For 100% of data, 1≤n≤1,000,1≤m≤10,000,0≤k≤100,000,0≤di≤100,0≤ti≤100,000.

/*just started to do only 10 points, should be greedy ideas have a problem tim[i] to arrive at the moment of the I station last[i] means I station's departure at the latest time Sum[i] indicates the number of people before or at I station f[i] indicates the number of points at the I station where an accelerator may affect ( Placing an accelerator at the I station will have an effect on the point behind the part)*/#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#defineN 10010using namespacestd;intF[n],sum[n],dis[n],b[n],last[n],tim[n];intN,m,k,total,ans;intMain () {scanf ("%d%d%d",&n,&m,&k);  for(intI=1;i< n;i++) scanf ("%d",&Dis[i]);  for(intI=1; i<=m;i++)     {        intA,c; scanf ("%d%d%d",&c,&a,&B[i]); Total+=C; Last[a]=Max (LAST[A],C);  for(intj=b[i];j<=n;j++) Sum[j]++; }     while(k--)    {         for(intI=2; i<=n;i++) Tim[i]=max (tim[i-1],last[i-1]) +dis[i-1]; F[n]=0;  for(inti=n-1; i;i--)         if(tim[i+1]>last[i+1])//last as a qualifying conditionf[i]=f[i+1]+1; Elsef[i]=1; intmaxn=-1, maxpos=0;  for(intI=1; i<n;i++)          if(dis[i]&&f[i]&&sum[f[i]+i]-sum[i]>MAXN) {MAXN=sum[f[i]+i]-Sum[i]; Maxpos=i; }        if(Maxpos) dis[maxpos]--; }     for(intI=2; i<=n;i++) Tim[i]=max (tim[i-1],last[i-1]) +dis[i-1];  for(intI=1; i<=m;i++) ans+=Tim[b[i]]; printf ("%d", ans-Total );}
View Code

Sightseeing bus (Codevs 1139)

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.