题目总版

Gx120905 @ 2024-11-25 18:31:14

P9749 [CSP-J 2023] 公路(我错在哪?)

#include <bits/stdc++.h>
using namespace std;

long long c[100005] = {0}, d[100005] = {0};

int main() {
    long long a = 0, b = 0, g = 0;
    cin >> a >> b;

    for (int i = 0; i < a - 1; i++) {

        cin >> c[i];
    }

    for (int i = 0; i < a; i++) {

        cin >> d[i];
    }

    int i = 0, last = 0;

    while (i != a - 1) {
        int j = i + 1, len = 0;
        len += c[i];

        while (j < a - 1 && d[j] >= d[i]) {
            len += c[j];
            j++;
        }

        len -= last;
        int x = len / b;

        if (len % b != 0) {
            x++;
        }

        g += x * d[i];
        last = x * b - len;
        i = j;
    }

    cout << g;
}

|