88072024-01-31 10:04:19Error42Rendőrségi Üldözés 4cpp17Accepted 100/100463ms4684 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;

ll first_green(ll const cur_t, ll const t) {
    ll cycle = cur_t % (2 * t);

    if (cycle < t)
        return cur_t;
    else
        return cur_t / (2 * t) * (2 * t) + 2 * t;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n, r, t, l;
    cin >> n >> r >> t >> l;

    vector<ll> x(n);
    for (ll& y : x)
        cin >> y;

    vector<ll> dp(r + 1);

    for (int i = 0; i <= r; i++)
        dp[i] = x[0];

    for (int i = 0; i < n; i++) {
        // get through lamp
        for (int j = r; j >= 1; j--) {
            dp[j] = min(first_green(dp[j], t), dp[j - 1]);
        }
        dp[0] = first_green(dp[0], t);

        // to next lamp
        if (i != n - 1) {
            for (int j = 0; j <= r; j++)
                dp[j] += x[i + 1] - x[i];
        }
    }

    cout << dp[r] + l - x.back() << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1700 KiB
2Accepted3ms1864 KiB
subtask210/10
3Accepted3ms2096 KiB
4Accepted3ms2268 KiB
5Accepted2ms2348 KiB
6Accepted2ms2356 KiB
7Accepted3ms2572 KiB
subtask315/15
8Accepted3ms2788 KiB
9Accepted3ms2900 KiB
10Accepted2ms2992 KiB
11Accepted3ms3104 KiB
subtask415/15
12Accepted3ms3112 KiB
13Accepted3ms3312 KiB
14Accepted3ms3448 KiB
15Accepted3ms3656 KiB
subtask525/25
16Accepted2ms3580 KiB
17Accepted2ms3584 KiB
18Accepted3ms3576 KiB
19Accepted3ms3584 KiB
20Accepted3ms3888 KiB
subtask615/15
21Accepted3ms3756 KiB
22Accepted3ms3648 KiB
23Accepted3ms3640 KiB
24Accepted3ms3908 KiB
25Accepted3ms3916 KiB
subtask720/20
26Accepted8ms4072 KiB
27Accepted18ms4092 KiB
28Accepted50ms4356 KiB
29Accepted156ms4640 KiB
30Accepted463ms4684 KiB