先预处理每一个点往前退几步

就一个trick。。要处理这一秒已经超出了要拿完所花的时间

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
typedef __int64 ll;
using namespace std; int c[100005],w[100005],s[100005],t[100005],tmp,N,n,m,k,i,cnt,pos,ans; int main()
{
while(~scanf("%d%d%d",&n,&m,&k))
{
for(i=1;i<=n;i++)
scanf("%d",&w[i]);
for(i=1;i<=m;i++)
scanf("%d",&t[i]);
s[n]=w[n];
tmp=n-1;
cnt=1;
while(s[n]<=k&&tmp>0)
{
s[n]+=w[tmp];
tmp--;
cnt++;
}
c[n]=cnt;
N=n-1;
while(N)
{
s[N]=s[N+1]-w[N+1];
cnt--;
while(s[N]<=k&&tmp>0)
{
s[N]+=w[tmp];
tmp--;
cnt++;
}
c[N]=cnt;
// printf("N:%d cnt:%d tmp:%d\n",N,cnt,tmp);
if(tmp<=0)
{
for(i=N;i>0;i--)
{
c[i]=i;
}
break;
}
N--;
}
//处理每一个分散注意力的秒
sort(t+1,t+m+1);
t[0]=0;
ans=0;
pos=0;
for(i=1;i<=m;i++)
{
tmp=(t[i]-t[i-1]);
pos+=tmp;
if(pos>n){//时间超出了全部拿完的时间
pos-=tmp;
break;
}
ans+=tmp;
pos=pos-1-c[pos-1]; }
ans+=(n-pos);
printf("%d\n",ans);
}
return 0;
}

ural 1998 The old Padawan的更多相关文章

  1. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  2. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  3. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  4. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  5. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  6. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  7. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

  8. ural 2066. Simple Expression

    2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...

  9. ural 2065. Different Sums

    2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...

随机推荐

  1. [Everyday Mathematics]20150119

    设 $V$ 是 $n$ 维线性空间, $V_1, V_2$ 均为 $V$ 的子空间, 且 $$\bex V_1\subset V_2,\quad \dim V=10,\quad \dim V_1=3, ...

  2. android 触摸事件、点击事件的区别

    针对屏幕上的一个View控件,Android如何区分应当触发onTouchEvent,还是onClick,亦或是onLongClick事件? 在Android中,一次用户操作可以被不同的View按次序 ...

  3. 如何清除win7开机密码

    一.电脑已经登录到系统,但是忘记了密1对于这种情况是最简单的,其实只需要将密码取消就可以了右键单击桌面上我的电脑,选择管理即可进入计算机管理界面2依次展开系统工具--本地用户和组--用户,在右侧选择要 ...

  4. Delphi 操作Word怎么控制光标的位置

    unit ControlWordS; interface uses Classes, Sysutils, Word97; type  TControlWord = class(TComponent)  ...

  5. <转>ERP的测试用例模板

    1页面部分(1) 页面清单是否完整(是否已经将所需要的页面全部都列出来了)(2) 页面是否显示(在不同分辨率下页面是否存在,在不同浏览器版本中页面是是否显示)(3) 页面在窗口中的显示是否正确.美观( ...

  6. RTNETLINK answers: File exists错误

    解决ssh连接虚拟机出错,RTNETLINK answers: File exists 解决步骤如下: 使用ssh连接虚拟机的时候,发现目标主机无法连接,登录虚拟机,查看ssh监听是否开启: 发现监听 ...

  7. Nonlinear Transform

    前文中,我们已经学习了linear classification,linear regression,logistic regression三种线性方法. 如何解决这种问题呢? 其实很好解决,只需要加 ...

  8. java 中 正则 正则表达式 匹配 url

    不多说 [http|https]+[://]+[0-9A-Za-z:/[-]_#[?][=][.][&]]* 这个就是匹配 网络上的网址 又称 url . 最起码 绝大部分的taobao ur ...

  9. [置顶] Kendo UI开发教程: Kendo UI 示例及总结

    前面基本介绍完Kendo UI开发的基本概念和开发步骤,Kendo UI的示例网站为http://demos.kendoui.com/ ,包含了三个部分 Web DemoMobile DemoData ...

  10. 使用Core Data应避免的十个错误

    原文:Avoiding Ten Big Mistakes iOS Developers Make with Core Data   http://www.cocoachina.com/applenew ...