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

就一个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. POJ 1423 Big Number

    题意:求n阶乘的位数. 解法:斯特林公式,,然后取log10就是位数了,因为精度问题需要化简这个式子,特判1. 代码: #include<stdio.h> #include<iost ...

  2. [Papers]NSE, $\p_3u$, multiplier spaces [Guo-Gala, ANAP, 2013]

    $$\bex \p_3\bbu\in L^\frac{2}{1-r}(0,T;\dot X_r(\bbR^3)),\quad 0\leq r\leq 1. \eex$$

  3. JAX-WS

    JAX-WS(Java API for XML Web Services)规范是一组XML web services的JAVA API,JAX-WS允许开发者可以选择RPC-oriented或者mes ...

  4. uC/OS - III 移植 IAR平台

    关于移植uC/OS-III 网上已经有很多教程了此处只是做个记录 首先下载源码然后解压得到下面的文件: 然后在模版工程里新建各种文件夹: 最后全部都添加进工程: OK了,编译一下,惊呆了,竟然 0错误 ...

  5. XSLT 调用java

    XSLT调用JS  http://www.ibm.com/developerworks/cn/xml/tips/x-tipxsltjs/index.htmlXSLT调用JAVA  http://unm ...

  6. ORA-15018: diskgroup cannot be created

    创建ASM磁盘组的时候出错,具体报错如下: SQL> create diskgroup kel external redundancy disk 'ORCL:KEL1','ORCL:KEL2'; ...

  7. JQuery:各种操作表单元素方法小结

    来源:http://www.ido321.com/1220.html 表单元素无处不在,已然成了Web应用不可或缺的一个部分.对表单最最最常见的操作就是获取表单元素的值或者更改表单元素的值.那在JQu ...

  8. 多校7 HDU5818 Joint Stacks

    多校7 HDU5818 Joint Stacks 题意:n次操作.模拟栈的操作,合并的以后,每个栈里的元素以入栈顺序排列 思路:开三个栈,并且用到了merge函数 O(n)的复杂度 #include ...

  9. POJ-1002 解题报告

      1.题目描述 http://poj.org/problem?id=1002 2.解题过程 按部就班来解题的话,这个题目很容易写出来,这是我的第一个版本的代码,思路是读入一行电话字符串,均转化为整型 ...

  10. Linux重复执行上条命令

    Linux系统下Shell重复执行上条命令的 4 种方法: 1.使用上方向键,并回车执行.2.按 !! 并回车执行.3.输入 !-1 并回车执行.4.按 Ctrl+P 并回车执行.