[codeforces 241]A. Old Peykan
[codeforces 241]A. Old Peykan
试题描述
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kilometers long.
The Old Peykan travels 1 kilometer in 1 hour and consumes 1 liter of fuel during this time.
Each city ci (except for the last city cn) has a supply of si liters of fuel which immediately transfers to the Old Peykan if it passes the city or stays in it. This supply refreshes instantly k hours after it transfers. The Old Peykan can stay in a city for a while and fill its fuel tank many times.
Initially (at time zero) the Old Peykan is at city c1 and s1 liters of fuel is transferred to it's empty tank from c1's supply. The Old Peykan's fuel tank capacity is unlimited. Old Peykan can not continue its travel if its tank is emptied strictly between two cities.
Find the minimum time the Old Peykan needs to reach city cn.
输入
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1.
The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1, s2, ..., sm (1 ≤ si ≤ 1000).
输出
输入示例
输出示例
数据规模及约定
见“输入”
题解
先尽量往右走,发现油量不够时再把加油的时间补回来,因为 k 是固定的,而且没经过一个城市就能在瞬间得到这个城市拥有的油量,所以只要加油时贪心地每次都取当前经过的所有城市中拥有最多油量的城市即可。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 1010
#define LL long long
int n, k, d[maxn], s[maxn]; int main() {
n = read(); k = read();
for(int i = 1; i <= n; i++) d[i] = read();
for(int i = 1; i <= n; i++) s[i] = read(); int ni = 1, mx = 0;
LL nt = 0, ns = 0;
for(; ni <= n + 1;) {
mx = max(mx, s[ni]);
ns += s[ni];
if(ns >= d[ni]) ;
else {
int x = (d[ni] - ns) / mx;
if(mx * x == (d[ni] - ns)) ; else x++;
nt += (LL)x * k;
ns += (LL)x * mx;
}
ns -= d[ni]; nt += d[ni]; ni++;
} printf("%I64d\n", nt); return 0;
}
[codeforces 241]A. Old Peykan的更多相关文章
- [codeforces 241]C. Mirror Box
[codeforces 241]C. Mirror Box 试题描述 Mirror Box is a name of a popular game in the Iranian National Am ...
- Codeforces Round #241 (Div. 2)->B. Art Union
B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #241 (Div. 2)->A. Guess a number!
A. Guess a number! time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #241 (Div. 2) B. Art Union 基础dp
B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #241 (Div. 2) B dp
B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #241 (Div. 2) B. Art Union (DP)
题意:有\(n\)个画家,\(m\)幅画,每个画家负责\(m\)幅画,只有前一个画家画完时,后面一个画家才能接着画,一个画家画完某幅画的任务后,可以开始画下一幅画的任务,问每幅画最后一个任务完成时的时 ...
- CodeForces比赛总结表
Codeforces A B C D ...
- Codeforces 714C. Sonya and Queries Tire树
C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...
- CodeForces - 416A (判断大于小于等于 模拟题)
Guess a number! Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
随机推荐
- [poj3274]排排站(Hash)
题目:http://poj.org/problem?id=3274 题目大意:http://www.wikioi.com/problem/1247/ (此题中文版) 分析: 令sum[i][j]表示a ...
- Linq之IQueryable接口与IEnumberable区别
IEnumerable接口 公开枚举器,该枚举器支持在指定类型的集合上进行简单迭代.也就是说:实现了此接口的object,就可以直接使用foreach遍历此object: IEnumerable 包含 ...
- 第三十九课:requestAnimationFrame详解
大家应该都知道,如果一个页面运行的定时器很多,无论你怎么优化,最后肯定会超过指定时间才能完成动画.定时器越多,延时越严重. 为此,YUI,kissy等采用中央队列的方式,将定时器减少至一个.浏览器厂商 ...
- java--- Map详解
Map简介 将键映射到值的对象.一个映射不能包含重复的键:每个键最多只能映射到一个值.此接口取代 Dictionary 类,后者完全是一个抽象类,而不是一个接口. Map 接口提供三种collecti ...
- 什么是POJO?
本文转载自百度文库,详细出处请参考: http://wenku.baidu.com/view/4a9ad533ee06eff9aef80765.html 我认为写的很准确,很抱歉没有找到作者的名字! ...
- BZOJ-2190 仪仗队 数论+欧拉函数(线性筛)
今天zky学长讲数论,上午水,舒爽的不行..后来下午直接while(true){懵逼:}死循全程懵逼....(可怕)Thinking Bear. 2190: [SDOI2008]仪仗队 Time Li ...
- 【bzoj2115】 Xor
www.lydsy.com/JudgeOnline/problem.php?id=2115 (题目链接) 题意 给出一张图,可能有重边和自环,在图中找出一条从1-n的路径,使得经过的路径的权值的异或和 ...
- poj 1006 中国剩余定理解同余方程
其实画个图就明白了, 该问题就是求同余方程组的解: n+d≡p (mod 23) n+d≡e (mod 28) n+d≡i (mod 33) #include "iostream" ...
- unix/linux进程详解
技术分享 启动新进程 stdlib.hintsystem(const char *string)whichequals to "sh -c string" 替换进程映像unistd ...
- ECSHOP验证码背景图修改教程
ECSHOP验证码背景图修改教程 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2013-11-18 ECSHOP验证码背景图修改教程: ECSHOP前后台的某些地 ...