点击打开题目链接

1998. The old Padawan

Time limit: 0.5 second
Memory limit: 64 MB
Yoda: Use the Force. Yes. Now, the stone. Feel it. Concentrate!
Luke Skywalker is having exhausting practice at a God-forsaken planet Dagoba. One of his main difficulties is navigating cumbersome objects using the Power. Luke’s task is to hold several stones in the air simultaneously. It takes complete concentration and attentiveness but the fellow keeps getting distracted.
Luke chose a certain order of stones and he lifts them, one by one, strictly following the order. Each second Luke raises a stone in the air. However, if he gets distracted during this second, he cannot lift the stone. Moreover, he drops some stones he had picked before. The stones fall in the order that is reverse to the order they were raised. They fall until the total weight of the fallen stones exceeds k kilograms or there are no more stones to fall down.
The task is considered complete at the moment when Luke gets all of the stones in the air. Luke is good at divination and he can foresee all moments he will get distracted at. Now he wants to understand how much time he is going to need to complete the exercise and move on.

Input

The first line contains three integers: n is the total number of stones, m is the number of moments when Luke gets distracted and k (1 ≤ nm ≤ 105, 1 ≤ k ≤ 109). Next n lines contain the stones’ weights wi (in kilograms) in the order Luke is going to raise them (1 ≤ wi ≤ 104). Next m lines contain moments ti, when Luke gets distracted by some events (1 ≤ ti ≤ 109, ti < ti+1).

Output

Print a single integer — the number of seconds young Skywalker needs to complete the exercise.

Sample

input output
5 1 4
1
2
3
4
5
4
8

Hint

In the first three seconds Luke raises stones that weight 1, 2 and 3 kilograms. On the fourth second he gets distracted and drops stones that weight 2 and 3 kilograms. During the next four seconds he raises all the four stones off the ground and finishes the task.

题意:有一个人要举起m块石头,但是在举石头的过程中容易走神,在他走神的1s内,要向前掉至少Kkg的石头,求其至少多少步才能把石头都举起来。

二分判断现在举起的石头还有多少。然后一步一步来。


代码:

#include <cstdio>
#include <cstring>
#include<iostream>
#include<queue>
#include <algorithm>
#define N 100005
using namespace std;
int n,m,k;
int w[N],t[N],s[N];
int binary(int x)
{int l=0,r=n,mid,ss=0;while(l<=r){mid=(l+r)/2;if(s[mid]<x){ l=mid+1;ss=mid;}elser=mid-1;}return ss;
}
int main()
{while(~scanf("%d%d%d",&n,&m,&k)){memset(s,0,sizeof(s));memset(w,0,sizeof(s));memset(t,0,sizeof(s));for(int i=1;i<=n;i++){scanf("%d",&w[i]);s[i]=s[i-1]+w[i];}for(int i=1;i<=m;i++)scanf("%d",&t[i]);t[++m]=2e9;int sum=0,tmp=0,p=0;for(int i=1;i<=m;i++){if(n-p<t[i]-sum){sum+=n-p;break;}else{tmp=t[i]-sum+p;sum+=t[i]-sum;p=binary(s[tmp-1]-k);}}printf("%d\n",sum);}return 0;
}

Ural 1998 The old Padawan(二分)相关推荐

  1. URAL 1998 The old Padawan 二分

    The old Padawan 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1998 Description Yoda: Use th ...

  2. ural 1998 The old Padawan (模拟+二分)

    题意: 有一个人捡按一定顺序捡石头,每秒都能捡起一个,但是他有时会分心,这是不但不能举石头, 而且手中的石头还会掉,直到没有石头可以掉下来或者掉下来的石头的总重量>k.依次给出n个 石头的重量和 ...

  3. URAL 1998 The old Padawan

    题目只给了500ms,注意超时问题,一开始的几发都超时了,后来想到了预处理,从后往前推即可,为了防止t的大小可能有问题,所以进行了排序,还有人用二分做的,比较犀利先贴一个我的思路 #include&l ...

  4. ural 1998 The old Padawan

    先预处理每一个点往前退几步 就一个trick..要处理这一秒已经超出了要拿完所花的时间 #include <iostream> #include <cstring> #incl ...

  5. URAL 1156 Two Rounds (DFS二分染色 + 分组背包)

    #include <stdio.h> #define MAX 110int numOfTasks, numOfPairs; int numOfProblems; typedef struc ...

  6. I - The old Padawan Gym - 100285I——二分查找

    Think: 1知识点:二分查找+前缀和 2题意:n个石子,m次发呆,每次发呆若手中石子足够掉落石子大于k,询问将所有石子拾到手中所需要的时间 3反思:多理解,多反思,多思考 vjudge题目链接 以 ...

  7. GYM 100285 I. The old Padawan(二分+简单模拟)

    Description 有一个人捡按一定顺序捡石头,每秒都能捡起一个,但是他有时会分心,这是不但不能举石头,而且手中的石头还会掉,直到没有石头可以掉下来或者掉下来的石头的总重量>k.依次给出n个 ...

  8. POJ - 2002 Squares 数正方形【二分】【哈希表】

    Squares POJ - 2002 题意 平面上有N个点,任取4个点,求能组成正方形的不同组合方式有多少种:相同的四个点,不同顺序构成的正方形视为同一正方形 分析 做法1 先枚举两个点,通过计算得到 ...

  9. StringBuffer+排序+二分查找+包装类+正则表达式+常用类

    一.StringBuffer 1.概述 我们如果对字符串进行拼接操作,每次拼接,都会构建一个新的String对象,既耗时,又浪费空间.而StringBuffer就可以解决这个问题StringBuffe ...

最新文章

  1. python100行代码-python代码统计 100行
  2. CloudFoundry的cf push命令执行后,背后发生了什么
  3. 大学计算机科学不会编码,华中科技大学人员编号编码管理办法
  4. 2.4 1死锁的概念(1)
  5. solr集群搭建,zookeeper集群管理
  6. linux screen 命令是 ssh 的有效补充
  7. R语言编程基础(1)
  8. 2018今日头条大数据方向笔试题
  9. 零基础、转行学习Python是否还在纠结?这里告诉你答案!
  10. 可能促使您决定创建自定义数据绑定控件的一些原因:
  11. Sonar安装和常见问题解决
  12. DEDECMS安装遇到NO input files specified解决方案
  13. xposed框架android9.0,xposed仓库商店下载
  14. 原生js导出excel,并保留样式
  15. MySQL的JDBC下载
  16. [QualComm] RamDump log收集
  17. redhat linux 系统修复,简述rhel7系统修复
  18. java tld文件配置_Java Web应用因tld文件损坏出现的错误
  19. memmove函数c语言实现,【C语言】实现memcopy、memmove函数
  20. C语言中的光标定位函数

热门文章

  1. Ext.form.TextField与Ext.form.TextArea
  2. 【软考备战·希赛网每日一练】2023年4月21日
  3. vue2.0,vue3.0 v-model数据双向绑定
  4. 占位图和图片懒加载项目实战详解
  5. 免费python课程-Python零基础免费入门课程
  6. Linux云计算之web 平台搭建(LAMP-CtenOS 6)
  7. encode deencode
  8. 使用TypeScript开发微信小程序的方法
  9. window10总提示幸福倒计时,解决方法
  10. 收敛速度:线性收敛,超线性收敛,r 阶收敛