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

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

  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4. #include <cstdio>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <queue>
  9. #include <map>
  10. #define inf 0x3f3f3f3f
  11. typedef __int64 ll;
  12. using namespace std;
  13.  
  14. int c[100005],w[100005],s[100005],t[100005],tmp,N,n,m,k,i,cnt,pos,ans;
  15.  
  16. int main()
  17. {
  18. while(~scanf("%d%d%d",&n,&m,&k))
  19. {
  20. for(i=1;i<=n;i++)
  21. scanf("%d",&w[i]);
  22. for(i=1;i<=m;i++)
  23. scanf("%d",&t[i]);
  24. s[n]=w[n];
  25. tmp=n-1;
  26. cnt=1;
  27. while(s[n]<=k&&tmp>0)
  28. {
  29. s[n]+=w[tmp];
  30. tmp--;
  31. cnt++;
  32. }
  33. c[n]=cnt;
  34. N=n-1;
  35. while(N)
  36. {
  37. s[N]=s[N+1]-w[N+1];
  38. cnt--;
  39. while(s[N]<=k&&tmp>0)
  40. {
  41. s[N]+=w[tmp];
  42. tmp--;
  43. cnt++;
  44. }
  45. c[N]=cnt;
  46. // printf("N:%d cnt:%d tmp:%d\n",N,cnt,tmp);
  47. if(tmp<=0)
  48. {
  49. for(i=N;i>0;i--)
  50. {
  51. c[i]=i;
  52. }
  53. break;
  54. }
  55. N--;
  56. }
  57. //处理每一个分散注意力的秒
  58. sort(t+1,t+m+1);
  59. t[0]=0;
  60. ans=0;
  61. pos=0;
  62. for(i=1;i<=m;i++)
  63. {
  64. tmp=(t[i]-t[i-1]);
  65. pos+=tmp;
  66. if(pos>n){//时间超出了全部拿完的时间
  67. pos-=tmp;
  68. break;
  69. }
  70. ans+=tmp;
  71. pos=pos-1-c[pos-1];
  72.  
  73. }
  74. ans+=(n-pos);
  75. printf("%d\n",ans);
  76. }
  77. return 0;
  78. }

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. FOJ 1858 Super Girl 单调队列

    http://acm.fzu.edu.cn/problem.php?pid=1858 一个数组中  找两对元素,第一对元素和最大,第二对元素和最小,限制:一对元素中两个元素的距离在原数组中小于d.去掉 ...

  2. Richedit使用大全

    原文地址:http://blog.csdn.net/pcseye/article/details/3903333 一.常见问题 a.可以编译,不能执行的 AfxInitRichEdit(); b.升级 ...

  3. 在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world

    一.题目 编写一个内核模块,在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world.内核版本要求2.6.18 二.实验环境 物理主机:w ...

  4. 用Vmware安装centos5

    Vmware安装过程就不详述了,这里从创建虚拟机开始记录. 选择创建虚拟机 下一步 选择稍后安装 选择安装的操作系统版本,需要说明的是,CentOs 5 就是RHEL 5 设置虚拟机名称及虚拟机位置 ...

  5. C语言基础知识--位运算

    1.原码,反码,补码: (1)在n位的机器数中,最高位为符号位,该位为零表示为正,为一表示为负:其余n-1位为数值位,各位的值可为零或一.当真值为正时,原码.反码.补码数值位 完全相同:当真值为负时, ...

  6. C# 与 VC Dll 传输信息

    考虑: 使用string类型传送: 在VC Dll中解析字符: 使用 string 类型将解析的类型传送到C#程序中: 建立VC解析的函数,提高代码可重用性

  7. Bmob第三方登录详解

    Bmob第三方登录详解 Bmob 第三方登录 简介 本文主要介绍新浪微博,QQ,微信的登录接入以及如何配合BmobSDK中的第三方登录功能实现第三方登录. 在使用之前请先按照快速入门创建好可以调用Bm ...

  8. ubuntu安装hudson

    因为hudson需要依赖java等,手动安装比较费劲 官方给出了一种很简单的解决方案:http://wiki.eclipse.org/Hudson-ci/Installing_Hudson_DEB s ...

  9. -bash: ./radar.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录

    运行shell脚本时,报下面这个错误:   -bash: ./radar.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录 错误分析: 因为操作系统是windows, ...

  10. cloud maintenance of OpenNebula

    OpenNebula 4.4.1 maintenance release,官方建议当前的生产环境使用3.x or 4.x的其它版本; php调用curl工具伪造ip Upgrading from Op ...