30贪心求调
查看原帖
30贪心求调
632063
shipeiqian楼主2024/10/4 15:35
#include <bits/stdc++.h>
#define de "debug "
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,d,dis[N],val[N];
int main(){
#ifndef ONLINE_JUDGE
    freopen("Input.in","r",stdin);
    freopen("Output.out","w",stdout);
#endif
    //ios::sync_with_stdio(false);
    cin >>n >>d;
    for(int i=1;i<n;i++)cin >>dis[i];
    for(int i=1;i<=n;i++)cin >>val[i];
    ll nowdis=0,ans=0,mn=1e9+7;
    for(int i=1;i<n;i++){
        mn=min(mn,val[i]);
        ll t=dis[i]-nowdis;
        if(t<=0)continue;
        ll need=t/d+(t%d?1:0);
        nowdis=need*d-dis[i];
//        cout <<i <<" " <<need <<"\n";
        ans+=need*mn;
    }
    cout <<ans;
    return 0;
}
2024/10/4 15:35
加载中...