求助!只有五分
查看原帖
求助!只有五分
1112264
YZZCDS楼主2024/7/26 10:47
#include <bits/stdc++.h>
using namespace std;
typedef long long l;
l n, v[100005], a[100005], d, dis, money, mn;
deque<pair<l, l>> q;
int main() {
	cin >> n >> d;
	for (int i = 1; i < n; i ++) {
		cin >> v[i];
	}
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	q.push_back(pair<l, l>{0, a[1]});
	for (int i = 2; i <= n; i ++) {
		dis += v[i-1];
		if (q.back().second > a[i]) {
			q.push_back(pair<l, l>{dis, a[i]});
			dis = 0;
		}
	}
    while (!q.empty()) {
        mn = q.front().second;
        q.pop_front();
        money += ceil((double)q.front().first / d) * mn;
    }
    cout << money << endl;
	return 0;
}

2024/7/26 10:47
加载中...