The old Padawan

题目连接:

http://acm.timus.ru/problem.aspx?space=1&num=1998

Description

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 ≤ n, m ≤ 10 5, 1 ≤ k ≤ 10 9). Next n lines contain the stones’ weights wi (in kilograms) in the order Luke is going to raise them (1 ≤ wi ≤ 10 4). Next m lines contain moments ti, when Luke gets distracted by some events (1 ≤ ti ≤ 10 9, ti < ti+1).

Output

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

Sample Input

5 1 4
1
2
3
4
5
4

Sample Output

8

Hint

题意

这个人每秒钟会捡起来一个物品

这个人会在某些时间发呆,如果发呆的话,他会一直丢下物品,直到丢完或者丢下价值和超过k的物品

丢下去的顺序是捡起来顺序的倒叙

问你最少多少秒,可以把所有东西都捡起来

题解:

对于发呆这个东西,直接二分就好了,二分一直丢到哪儿

代码

#include<bits/stdc++.h>
using namespace std;
const long long inf = 1LL<<50;
const int maxn = 1e5+7;
long long sum[maxn],t[maxn],a[maxn],k;
int n,m;
int main()
{scanf("%d%d%lld",&n,&m,&k);for(int i=1;i<=n;i++)scanf("%lld",&a[i]);for(int i=n;i>=1;i--)sum[i]=sum[i+1]+a[i];for(int i=1;i<=m;i++)scanf("%lld",&t[i]);t[m+1] = inf;sum[0] = inf;int now = 0;long long ans = 0;int j = 1;while(1){if(j==m+1){ans = ans + n - now;break;}if(t[j]>ans+n-now){ans = ans + n - now;break;}now = now + (t[j]-t[j-1]) - 1;int l = 0,r = now,Ans = 1;while(l<=r){int mid = (l+r)/2;if(sum[mid]-sum[now+1]>k)Ans=mid,l=mid+1;else r=mid-1;}now = Ans - 1;now = max(now,0);ans = t[j];j++;}cout<<ans<<endl;
}

转载于:https://www.cnblogs.com/qscqesze/p/5370323.html

URAL 1998 The old Padawan 二分相关推荐

  1. Ural 1998 The old Padawan(二分)

    点击打开题目链接 1998. The old Padawan Time limit: 0.5 second Memory limit: 64 MB Yoda: Use the Force. Yes. ...

  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. runtime的常用方法objc_setAssociatedObject的使用
  2. java等待_Java学习:等待唤醒机制
  3. 芯片,开源,数学,计算机
  4. 计算机管理员相关知识,计算机管理员述职报告范文
  5. 收购 GitHub 滔天争议后,微软回应一切
  6. 小伙用微信小程序的Canvas手撸了一个娃娃机
  7. log4j MDC用户操作日志追踪配置
  8. 北京最最最牛逼的 IT 公司全在这了!
  9. 普通话水平测试用朗读作品60篇-(练习版)
  10. 维修系统php源码,v3.4.0智睿报修管理系统
  11. 我的管理成长与思考 - 那些领导的真相,理解和思考
  12. 文件压缩原理是什么?
  13. 鸿蒙用户突破3亿,拳打谷歌安卓,脚踢苹果iOS
  14. python语言小程序-微信小程序可以用Python语言编写吗?
  15. vue 前端导出PDF文件学起来
  16. java计算机毕业设计HTML5“守护萌宠”网站设计与实现MyBatis+系统+LW文档+源码+调试部署
  17. 利用2阶分数阶微分掩模的边缘检测(Matlab代码实现)
  18. SSM框架+WebSocket实现网页聊天(Spring+SpringMVC+MyBatis+WebSocket)
  19. 2021年第一季度中国电竞行业网络关注度分析报告
  20. 我们都一样,不甘平凡又害怕努力

热门文章

  1. repo的入门和使用
  2. 苹果怎么设置铃声?设置自己喜欢的歌曲作为铃声,一招搞定!
  3. ValueError: The truth value of a DataFrame is ambiguous. Use a.empty 解决办法。(附 if 深层理解)
  4. uniapp 的多选框传值
  5. 【Hello Network】HTTP协议
  6. STM32控制编码器电机实现【速度闭环控制】与【位置闭环控制】
  7. Dolphin scheduler在Windows环境下的部署与开发
  8. 程序员众生相——从乙方到甲方,我用了六年的时间
  9. ccache 3.1.9 发布,高速C/C++编译工具
  10. (四) 开集识别学习 open-set recognition(OSR)