luoguP1315 sightseeing bus

First time we can for each of the spots, find passengers departing from this attraction latest arriving. Denoted \ (T [i] \)

Then remember \ (Tim [i]] \ ) represents the bus from attractions \ (i \) minimum time of departure.

\[\therefore Tim[i]=\max(Tim[i-1],T[i-1])+d[i-1]\].

At the same time, we can find the number of passengers at every point to get off the \ (z_i \) .

Let us each a nitrogen accelerator for processing.

For each road connecting the two attractions \ (d_i \) , we can find in the \ (d_i \) using a nitrogen can affect the accelerator up to the farthest points of interest \ (nxt_i \) .

So we can each \ (D_i \) , which is calculated on the accelerator with nitrogen profit \ (\ nxt_i SUM {^} _ {D_i} z_j J = \) , remove the maximum value, and \ (D_i \) from Less.

Repeat \ (k \) times.

#include<bits/stdc++.h>
#define il inline
#define rg register
#define gi read<int>
using namespace std;
const int N = 1e3 + 10, M = 1e4 + 10;
template<class TT>
il TT read() {
    TT o = 0,fl = 1; char ch = getchar();
    while (!isdigit(ch) && ch != '-') ch = getchar();
    if (ch == '-') fl = -1, ch = getchar();
    while (isdigit(ch)) o = o * 10 + ch - '0', ch = getchar();
    return fl * o;
}
int n, m, k, maxn, id, ans, d[N], a[M], b[M], t[M], z[N], T[N], nxt[N];
int main() {
    n = gi(), m = gi(), k = gi();
    for (int i = 1; i < n; ++i) d[i] = gi();
    for (int i = 1; i <= m; ++i) {
        t[i] = gi(), a[i] = gi(), b[i] = gi();
        ans -= t[i];
        T[a[i]] = max(T[a[i]], t[i]); ++z[b[i]];
    }
    for (int i = 2; i <= n; ++i) z[i] += z[i - 1];
    t[1] = 0;
    for (int i = 2; i <= n; ++i) t[i] = max(t[i - 1], T[i - 1]) + d[i - 1];
    for (int i = 1; i <= m; ++i) ans += t[b[i]];
    for (int i = k; i; --i) {
        maxn = 0, nxt[n] = nxt[n - 1] = n;
        for (int j = n - 2; j; --j)
            if (t[j + 1] <= T[j + 1]) nxt[j] = j + 1;
            else nxt[j] = nxt[j + 1];
        for (int j = 1; j <= n; ++j)
            if (z[nxt[j]] - z[j] > maxn && d[j])
                maxn = z[nxt[j]] - z[j], id = j;
        d[id]--; ans -= maxn;
        for (int j = 2; j <= n; ++j) t[j] = max(t[j - 1], T[j - 1]) + d[j - 1];
    }
    printf("%d\n", ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/lylyl/p/11704505.html