2 条题解
-
1
```#include<bits/stdc++.h> using namespace std ; const long long modd=1e9+7L; const int maxn=1e5+10; typedef pair<long,long>P; long long n,d,v[maxn],a[maxn],minn=1e18L,ans,you,yu,dis,cha; int main() { freopen("road.in","r",stdin); freopen("road.out","w",stdout); cin>>n>>d; for(int i=1;i<n;i++) cin>>v[i]; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<n;i++) { minn=min(minn,a[i]);dis-=v[i-1]; cha=v[i]-dis; if(cha<0)continue; you=cha/d;yu=cha%d; if(yu!=0)you++; ans+=you*minn;dis+=you*d; } cout<<ans; return 0; }
-
1
#include <bits/stdc++.h> #define int long long using namespace std; int n, d; int v[100000 + 5]; int a[100000 + 5]; signed main() { freopen("road.in", "r", stdin); freopen("road.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(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 ans = 0; // 总花费 int minPrice = a[1]; // 最低油价 int dis = 0; // 剩余里程 for(int i = 1; i <= n - 1; i++) { minPrice = min(minPrice, a[i]); if (dis < v[i]) { //剩余里程能跑多少跑多少 v[i] -= dis; dis = 0; } else { //全都用剩余里程跑 dis -= v[i]; v[i] = 0; } //有剩余路程需要买油跑 if (v[i]) { //花钱买油 ans += (v[i] / d + (v[i] % d != 0)) * minPrice; //剩余里程增加 dis += (v[i] / d + (v[i] % d != 0)) * d; //跑 dis -= v[i]; v[i] = 0; } } cout << ans << "\n"; return 0; }
- 1
信息
- ID
- 1348
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 8
- 标签
- 递交数
- 85
- 已通过
- 14
- 上传者