50求教
查看原帖
50求教
933437
Czenzi_QianXi楼主2024/10/21 20:38
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int a[N], b[N];
long long n, d, ans, y;
long long f(long long x)
{
    for(long long i = x + 1; i < n; i++)
    {
        if(b[i] < b[x]) return i;
    }
    return x;
}

int  main()
{
    cin >> n >> d;
    for(int i = 2; i <= n; i++)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for(int i = 1; i <= n; i++)
    {
        cin >> b[i];
    }
    long long i = 1;
    while(i != n)
    {
        long long findid = f(i);
        if(findid == i) findid = n;
        long long LL = a[findid] - a[i] - y;
        long long s = ceil(LL * 1.0 / d);
        if(s * d == LL) y = 0;
        else y = s * d - LL;
        ans += s * b[i];
        i = findid;
    }
    cout << ans;
    return 0;
}
2024/10/21 20:38
加载中...