P9749 [CSP-J 2023] 公路题解(%100数据)
  • 板块题目总版
  • 楼主Gx120905
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/22 18:54
  • 上次更新2024/11/22 18:56:19
查看原帖
P9749 [CSP-J 2023] 公路题解(%100数据)
1558494
Gx120905楼主2024/11/22 18:54
#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 (long long i = 0; i < a - 1; i++) {

		cin >> c[i];
	}

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

		cin >> d[i];
	}

	long long i = 0, last = 0;

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

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

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

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

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

	cout << g;
}
2024/11/22 18:54
加载中...