本文主要是介绍Acwing 5308 公路,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
5308. 公路 - AcWing题库
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#define endl '\n'
#define x first
#define y secondusing namespace std;typedef long long LL;
typedef pair<int,int> PII;const int N = 100010;int n,m;
LL ans,oil,dist;
int v[N],a[N];void solve()
{cin >> n >> m;for (int i = 1;i < n;i ++) cin >> v[i];for (int i = 1;i <= n;i ++) cin >> a[i];int price = a[1];for (int i = 2;i <= n;i ++){dist += v[i - 1]; //先更新距离LL t = (dist + m - 1) / m - oil; //需要多少油ans += t * price; //累加答案oil += t; //更新现在有的油量price = min(price,a[i]); // 更新最低油价}cout << ans << endl;
}int main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _ = 1;while(_--) solve();return 0;
}
这篇关于Acwing 5308 公路的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!