Treasure Hunt II


Time Limit: 2 Seconds                                     Memory Limit: 65536 KB                            

There are n cities(1, 2, ... ,n) forming a line on the wonderland. city i and city i+1 are adjacent and their distance is 1. Each city has many gold coins. Now, Alice and her friend Bob make a team to go treasure hunting. They starts at city p, and they want to get as many gold coins as possible in T days. Each day Alice and Bob can move to adjacent city or just stay at the place, and their action is independent. While as a team, their max distance can't exceed M.

Input

The input contains multiple cases. The first line of each case are two integers n, p as above. The following line contain n interger,"v1 v2 ... vn" indicate the gold coins in city i. The next line is M, T. (1<=n<=100000, 1<=p<=n, 0<=vi<=100000, 0<=M<=100000, 0<=T<=100000)

Output

Output the how many gold coins they can collect at most.

Sample Input

6 3
1 2 3 3 5 4
2 1

Sample Output

8

Hint

At day 1: Alice move to city 2, Bob move to city 4.
They can always get the gold coins of the starting city, even if T=0


Author: LI, Chao                                                     Contest: ZOJ Monthly, July 2012

题意 转自:http://blog.csdn.net/cscj2010/article/details/7819110

题意:n个城市排成一行,每个城市中有vi个金币。两个人同时从同一个个城市出发,单位时间能走到相邻城市。

  • 到达城市获取金币不耗时间,且任意时刻两人距离不可以超过m,问t个时间他们最多能获得多少金币。
  • 如果 m >= t * 2,两个人两个方向一直走
  • 否则 两人一直向两边走指导相距m,注意,若m为奇数,则某人要停走一天。
  • 然后维持距离同时向左向右枚举剩余天数
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<vector> #define N 100005
#define M 15
#define mod 1000000007
#define mod2 100000000
#define ll long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n,p;
ll v[N];
ll tot;
ll sum[N];
int m,t;
int t1,t2; void ini()
{
int i;
tot=;
memset(sum,,sizeof(sum));
for(i=;i<=n;i++){
//scanf("%lld",&v[i]);
cin>>v[i];
sum[i]=sum[i-]+v[i];
}
scanf("%d%d",&m,&t);
} void solve()
{
int i,j,o;
if(m/>=t)
{
i=max(,p-t);
j=min(n,p+t);
tot=sum[j]-sum[i-];
return ;
}
t1=min(t,m/);
t2=t-t1;
i=max(,p-t);
j=min(n,p+t1);
tot=sum[j]-sum[i-];
for(o=;o<=t2;o++){
i=max(,p-t1-o);
if(m%== && o!=){
j=max(p+t1,p+t1+t2-*o+);
j=min(n,j);
} else{
j=max(p+t1,p+t1+t2-*o);
j=min(n,j);
}
tot=max(tot,sum[j]-sum[i-]);
} j=min(n,p+t);
i=max(,p-t1);
tot=max(tot,sum[j]-sum[i-]);
for(o=;o<=t2;o++){
if(m%== && o!=){
i=min(p-t1,p-t1-t2+*o-);
i=max(,i);
} else{
i=min(p-t1,p-t1-t2+*o);
i=max(,i);
} j=min(n,p+t1+o);
// printf(" o=%d i=%d j=%d sum=%I64d\n",o,i,j,sum[j]-sum[i-1]);
tot=max(tot,sum[j]-sum[i-]);
}
//tot=v[p];
// i=max(p-t,1);
//if(i==1){
// tot=sum[]
// }
// j=min(p+1,n); } int main()
{
//freopen("data.in","r",stdin);
// scanf("%d",&T);
// for(int cnt=1;cnt<=T;cnt++)
// while(T--)
while(scanf("%d%d",&n,&p)!=EOF)
{
//if(g==0 && b==0 &&s==0) break;
ini();
solve();
//printf("%lld\n",tot);
cout<<tot<<endl;
} return ;
}

最新文章

  1. MYSQL数据库导入出错:#1046 - No database selected
  2. php sprintf 函数的用法
  3. struts之类型转换
  4. CABasicAnimation的delegate的坑
  5. 获取图片base64编码的几种方法
  6. NuGet安装和使用
  7. DSO、CUBE区别(覆盖、合计)
  8. Android Inflate
  9. aliyun install php apache mysql nginx
  10. 【现代程序设计】【homework-04】
  11. webserver/CGI
  12. 1、elasticsearch简介
  13. ActionBar隐藏修改图标和标题
  14. Unix/Linux环境C编程入门教程(7) OPENBSDCCPP开发环境搭建
  15. Qt之QNetworkInterface(查询网络接口),QHostInfo(查询主机IP)
  16. winform 之1---窗体介绍
  17. 从零开始一起学习SLAM | 掌握g2o顶点编程套路
  18. 手机浏览器 - 如何消除&lt;a&gt;标签在点击时的蓝色底色?
  19. 【Linux】【Jenkins】配置过程中,立即构建时,maven找不到的问题解决方案
  20. mybatis DATE_FORMAT 格式化时间输出

热门文章

  1. git快速入门(MAC系统,github,ssh key)
  2. Failed to configure a DataSource: &#39;url&#39; attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class
  3. shell 复合条件测试 if [ $1 == &quot;1&quot; -o $1 == &quot;0&quot; ] ------==和-eq怎么用
  4. 一、新手必会Python基础
  5. pip install mysqlclient 报错:error: Microsoft Visual C++ 14.0 is required.
  6. 命令行发送UDP
  7. 【php】 php-fpm 配置见解
  8. MySQL 之视图、 触发器、事务、存储过程、内置函数、流程控制、索引
  9. (转)UILabel常用属性
  10. 算法竞赛中c++一些需要注意的错误