30pts求调!
查看原帖
30pts求调!
1048358
zhiyinnitaimeiohbaby楼主2024/5/1 21:21
#include <bits/stdc++.h>
using namespace std;
double dis[100005];//distance
double cost[100005];//cost of oil per liter
long long cnt;//the cost overall
int main(){
	int sta,kpo;cin>>sta>>kpo; //input
	for(int i = 1;i < sta;i++){
		cin>>dis[i];//input
	}
	for(int i = 1;i <= sta;i++){
		cin>>cost[i];//input
	}
	int cheapest = 1;//the cheapest station now
	double oil_lasted = 0;//the oil in the car now
	for(int i = 1;i < sta;i++){
		if(cost[cheapest] > cost[i]){
			cheapest = i;//update the cheapest station
		}
		if(oil_lasted*kpo < dis[i]){//oil lasted can not support to drive to the next station
			cnt = cnt + ceil(dis[i]*1.0/kpo-oil_lasted)*cost[cheapest];//the cost of the oil we need to buy to drive to the nest station
			oil_lasted = ceil(dis[i]*1.0/kpo-oil_lasted)-dis[i]*1.0/kpo;//the oil lasted after driving to another station
		}
		else{
			oil_lasted-=dis[i]*1.0/kpo;//oil lasted can support to drive to the next station
		}
	}
	cout<<cnt;//output the answer
	return 0;
	}
2024/5/1 21:21
加载中...