NOIP2011 [improve group] sightseeing bus

Reproduced original contained in  https://blog.nowcoder.net/n/c3b27ff350044e53bd71acbf94e260f9  by Yan Chan school

Title Description

Scenic town of Y City, with n number of beautiful sights. As more and more tourists come here especially, Y City, specially arranged for a tour bus for tourists to provide more convenient transport services. Sightseeing bus at the first 0 minutes appears in the No. 1 spot, followed in turn went to 2,3,4 ...... n number of attractions. From the i-th open interest to the i + 1 of interest need Di minutes. At any moment, you can only drove on the bus, or waiting in the sights at.
Set up a total of m visitors, each visitor needs to travel to reach another 1 attractions from one attraction, the i guests came in spots Ai Ti minute, hoping to ride attractions Bi (Ai <Bi). To enable all passengers can reach their destinations smoothly, the bus must wait at every station after all passengers need to depart from the sights are on the train bound for departure to the next attraction.
Assume no time to get off the passengers.
A travel time of passengers, equal to his destination arrival time minus the time he came to the point of departure. Because only a sightseeing car, sometimes even stopped to wait for other passengers, passengers have complained about the travel time too long. So smart driver ZZ to k-bus nitrogen accelerators installed, each using one accelerator, which can make a minus Di 1. Di with respect to a reusable accelerator, but must ensure that after use Di is greater than or equal to 0.

So ZZ how to arrange the use of accelerators in order to minimize the total travel time for all passengers?

Enter a description

The first row 1 is 3 integer n, m, k, between two integers each separated by a space. Each represent the number of points of interest, the number of passengers and the number of nitrogen accelerator.
The first row is 2 n-1 integers, each separated by a space between two integers, it denotes the i-th time from the i-th interest bound i + 1-attractions in need, i.e., Di.
On line 3 to m + 2 lines each an integer of 3 Ti, Ai, Bi, each separated by a space between two integers. First i + 2 row represents the first time i went to passengers departing attractions, sights number of departure and arrival number of attractions.

Output Description

A total of one line containing an integer representing 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

10

Data range and tips

To use two accelerator D2, from 2 to 3 spots of interest time was changed to 2 minutes.
In the first bus from the No. 1 spot for 1 minute, 2 minutes to reach the No. 2 spots, the first 5 minutes from the No. 2 spots, 7 minutes to reach the No. 3 spot.
The first one passenger travel time 7-0 = 7 minutes.
The first two passenger travel time 2-1 = 1 minute.
The first three passenger travel time 7-5 = 2 minutes.
The total time of 7 + 2 + 1 = 10 minutes.

Data range
for 10% of the 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 data to 100%, n-1,000, ≤ ≤ ≤. 1 ≤ m ≤ K ≤ 10,000,0 100,000, of Ti ≤ Di ≤ 100,0 ≤ ≤ 100,000 .

 Thinking

Mouwang live on the cattle class, Chan Yan school chiefs talked about this question, the Internet proved not too perfect, he would prove himself a bit, according to him the whole network starting, too strong

Probably so be it, God ran too strong I still did not really understand

AC Code

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std; const int N = 1010,
 4     M = 10010;
 5  
 6 int n, m, k;
 7 int d[N];
 8 int t[M], a[M], b[M];
 9 int tm[N], last[N];
10 int sum[N];
11 int reduce[N];
12  
13 int main()
14 {
15     scanf("%d%d%d", &n, &m, &k);
16     for (int i = 1; i < n; i++) scanf("%d", &d[i]);
17     for (int i = 0; i < m; i++)
18     {
19         scanf("%d%d%d", &t[i], &a[i], &b[i]);
20         last[a[i]] = max(last[a[i]], t[i]);
21         sum[b[i]]++;
22     }
23  
24     for (int i = 1; i <= n; i++) tm[i] = max(tm[i - 1], last[i - 1]) + d[i - 1];
25  
26     while (k--)
27     {
28         for (int i = n; i >= 2; i--)
29             if (!d[i - 1]) reduce[i - 1] = 0;
30             else
31             {
32                 reduce[i - 1] = sum[i];
33                 if (tm[i] > last[i]) reduce[i - 1] += reduce[i];
34             }
35  
36         int p = 0;
37         for (int i = 1; i < n; i++)
38             if (reduce[p] < reduce[i])
39                 p = i;
40  
41         if (!p) break;
42         d[p]--;
43         for (int i = p + 1; i <= n; i++) tm[i] = max(tm[i - 1], last[i - 1]) + d[i - 1];
44     }
45  
46     int res = 0;
47     for (int i = 0; i < m; i++) res += tm[b[i]] - t[i];
48  
49     printf("%d\n", res);
50     return 0;
51 }

 

Guess you like

Origin www.cnblogs.com/Snowindfly/p/11279304.html