ural 1998 The old Padawan
先预处理每一个点往前退几步
就一个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的更多相关文章
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- 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 ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
- ural 2065. Different Sums
2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...
随机推荐
- FOJ 1858 Super Girl 单调队列
http://acm.fzu.edu.cn/problem.php?pid=1858 一个数组中 找两对元素,第一对元素和最大,第二对元素和最小,限制:一对元素中两个元素的距离在原数组中小于d.去掉 ...
- Richedit使用大全
原文地址:http://blog.csdn.net/pcseye/article/details/3903333 一.常见问题 a.可以编译,不能执行的 AfxInitRichEdit(); b.升级 ...
- 在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world
一.题目 编写一个内核模块,在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world.内核版本要求2.6.18 二.实验环境 物理主机:w ...
- 用Vmware安装centos5
Vmware安装过程就不详述了,这里从创建虚拟机开始记录. 选择创建虚拟机 下一步 选择稍后安装 选择安装的操作系统版本,需要说明的是,CentOs 5 就是RHEL 5 设置虚拟机名称及虚拟机位置 ...
- C语言基础知识--位运算
1.原码,反码,补码: (1)在n位的机器数中,最高位为符号位,该位为零表示为正,为一表示为负:其余n-1位为数值位,各位的值可为零或一.当真值为正时,原码.反码.补码数值位 完全相同:当真值为负时, ...
- C# 与 VC Dll 传输信息
考虑: 使用string类型传送: 在VC Dll中解析字符: 使用 string 类型将解析的类型传送到C#程序中: 建立VC解析的函数,提高代码可重用性
- Bmob第三方登录详解
Bmob第三方登录详解 Bmob 第三方登录 简介 本文主要介绍新浪微博,QQ,微信的登录接入以及如何配合BmobSDK中的第三方登录功能实现第三方登录. 在使用之前请先按照快速入门创建好可以调用Bm ...
- ubuntu安装hudson
因为hudson需要依赖java等,手动安装比较费劲 官方给出了一种很简单的解决方案:http://wiki.eclipse.org/Hudson-ci/Installing_Hudson_DEB s ...
- -bash: ./radar.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录
运行shell脚本时,报下面这个错误: -bash: ./radar.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录 错误分析: 因为操作系统是windows, ...
- cloud maintenance of OpenNebula
OpenNebula 4.4.1 maintenance release,官方建议当前的生产环境使用3.x or 4.x的其它版本; php调用curl工具伪造ip Upgrading from Op ...