样例过,0分,求助
查看原帖
样例过,0分,求助
965065
Wan__Ye__Chu楼主2024/7/29 16:45
#include<bits/stdc++.h>
using namespace std;

const int maxn=1e5+5;
long long n,d,m,s,o,qwq;//o=多走的路程 s=路程 m=价格 
long long v[maxn],a[maxn];

int main()
{
	//freopen("road2.in","r",stdin);
	//freopen("road2.out","w",stdout);
	ios::sync_with_stdio(0);
	cin>>n>>d;
	for(int i=1;i<=n-1;i++)
		cin>>v[i];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int j=1;
	while(j<n)
	{
		s=0;
		qwq=j-1;//上一次走到了哪个加油站 
		while(a[j]>=a[j+1] && j<n-1)
			j++;
		for(int i=qwq;i<=j-1;i++)	
			s+=v[i];
		if((s-o)%d==0)
		{
			m=m+((s-o)/d)*a[j];
			o=0;
		}	
		else
		{
			m=m+((s-o)/d+1)*a[j];
			o=o+((s-o)/d+1)*d-s;
		}	
		j++; 
		if(j==n)
		{
			if((s-o)%d==0)
			{
				m=m+((s-o)/d)*a[j];
				o=0;
			}	
			else
			{
				m=m+((s-o)/d+1)*a[j];
				o=o+((s-o)/d+1)*d-s;
			}	
				break;
		}
	}
	cout<<m<<endl;
	return 0;
}
2024/7/29 16:45
加载中...