/*
贪心 负数一定不取
枚举最高位是1 且答案取为0的 位置, 更新答案。
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define ll long long
#define N 100010 using namespace std;
int n;
ll a[N],ans,sum[N];
char s[N]; ll read()
{
ll x=,f=;char c=getchar();
while(c>''||c<''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int main()
{
freopen("maximum.in","r",stdin);
freopen("maximum.out","w",stdout);
scanf("%d",&n);
for(int i=; i<=n; i++)
{
a[i]=read();
sum[i]=sum[i-];
if(a[i]>)sum[i]=sum[i-]+a[i];
}
scanf("%s",s+);
ll c=;
for(int i=n; i>=; i--)
if(s[i]=='')
{
ans=max(ans,c+sum[i-]);
c+=max(a[i],0LL);
}
ans=max(ans,c);
printf("%I64d\n",ans);
return ;
}

/*
15暴力
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> #define N 1010 using namespace std;
int n,k;
int l,r,mid;
int num[N],tmp[N];
int ans; int minn(int a,int b,int i)
{
if(a<b) return tmp[i-];
else return tmp[i-]+mid;
} bool check()
{
int sum=;
for(int i=; i<=n; i++) tmp[i]=num[i];
for(int i=; i<=n; i++)
if(abs(tmp[i]-tmp[i-])>mid)
{
if(tmp[i+]>tmp[i]) tmp[i]=max(tmp[i],tmp[i-]+mid);
else tmp[i]=minn(abs(tmp[i-]-tmp[i+]),tmp[i-]+mid-tmp[i+],i);
sum++;
}
if(sum>k) return false;
else return true;
} int main()
{
scanf("%d%d",&n,&k);
for(int i=; i<=n; i++) scanf("%d",&num[i]);
l=;
r=;
while(l<=r)
{
mid=(l+r)/;
if(check()) ans=mid,r=mid-;
else l=mid+;
}
printf("%d",ans);
}

不会分块

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
const int maxn = ;
const int len = ;
int n, A, B,m;
int a[maxn],b[maxn],l[maxn],r[maxn],lb[maxn],tot;
int answer[][];
int rt[][maxn], lt[][maxn],d[maxn];
//int root[maxn*len], ll[maxn*len], rr[maxn*len],data[maxn*len];
int find(int x)
{
for (int l = , r = m; l < r;)
{
int mid = (l + r) / ;
if (b[mid] == x) return mid;
if (b[mid]>x) r = mid;
else l = mid + ;
}
return -;
}
/*int build(int l, int r)
{
if (l == r)
{
tot++;
ll[tot] = rr[tot] = 0;
data[tot] = d[l];
return tot;
}
tot++;
int tmp = tot;
ll[tmp] = build(l, (l + r) / 2);
rr[tmp] = build((l + r) / 2 + 1, r);
data[tmp] = min(data[ll[tmp]], data[rr[tmp]]);
return tmp;
}
int change(int i, int l, int r,int x)
{
if (l == x && r == x)
{
tot++;
ll[tot] = rr[tot] = 0;
data[tot] = n + 1;
return tot;
}
tot++;
int tmp = tot;
ll[tot] = ll[i];
rr[tot] = rr[i];
if (l <= x && x <= (l + r) / 2) ll[tmp] = change(ll[i], l, (l + r) / 2, x);
else rr[tmp] = change(rr[i], (l + r) / 2 + 1, r, x);
data[tmp] = min(data[ll[tmp]], data[rr[tmp]]);
return tmp;
}
int check(int i, int l, int r, int x, int &ans)
{
if (l > x) return 0;
if (1 <= l && r <= x)
{
ans = min(ans, data[i]); return 0;
}
check(ll[i], l, (l + r) / 2, x, ans);
check(rr[i], (l + r) / 2 + 1, r, x, ans);
return 0;
}*/
int main()
{
double ti = clock();
freopen("sequence.in", "r", stdin);
freopen("sequence.out", "w", stdout);
scanf("%d%d%d", &n, &A, &B);
a[] = ;
for (int i = ; i <= n; i++)
{
char c;
for (scanf(" %c", &c); c != 'A' && c != 'B'; scanf(" %c", &c));
if (c == 'A') a[i] = a[i - ] + B;
else a[i] = a[i - ] - A;
}
for (int i = ; i <= n; i++) b[i] = a[i];
sort(b, b + n + );
m = unique(b, b + n + ) - b;
for (int i = ; i <= n; i++)
{
a[i] = find(a[i]);
if (a[i] == -)
{
printf("???\n");
return ;
}
}
n++;
int k = n / len;
for (int i = ; i <= k; i++)
{
int ans = ;
tot++;
for (int j = i*len; j < n; j++)
{
if (j%len == )
{
answer[i][j / len] = ans;
}
if (lb[a[j]] != tot)
{
lb[a[j]] = tot;
l[a[j]] = j;
}
ans = max(ans, j - l[a[j]]);
}
}
for (int i = ; i < n; i++) r[i] = -;
for (int i = ; i < n; i++)
{
r[a[i]] = i;
if (i%len == len - )
{
int tmp = i / len;
for (int j = ; j < n; j++)
rt[tmp][j] = r[j];
}
}
for (int i = ; i < n; i++) l[i] = -;
for (int i = n - ; i >= ; i--)
{
l[a[i]] = i;
if (i%len == )
{
int tmp = i / len;
for (int j = ; j < n; j++)
lt[tmp][j] = l[j];
}
}
int q;
scanf("%d", &q);
int ans = ;
for (; q; q--)
{
int L, R;
scanf("%d%d", &L, &R);
L--;
int kl = L / len, kr = R / len;
ans = ;
if (kl == kr)
{
tot++;
for (int i = L; i <= R; i++)
{
if (lb[a[i]] != tot)
{
lb[a[i]] = tot;
l[a[i]] = i;
}
ans = max(ans, i - l[a[i]]);
}
}
else
{
ans = answer[kl + ][kr];
tot++;
int tmp = min(n, (kl + )*len);
for (int i = L; i < tmp; i++)
{
if (lb[a[i]] != tot)
{
lb[a[i]] = tot;
l[a[i]] = i;
ans = max(ans, rt[kr - ][a[i]] - i);
}
}
tmp = min(R + , n);
for (int i = kr*len; i < tmp; i++)
{
if (lb[a[i]] != tot)
{
if (lt[kl + ][a[i]] != -) ans = max(ans, i - lt[kl + ][a[i]]);
}
else ans = max(ans, i - l[a[i]]);
}
}
printf("%d\n", ans);
}
/*int q;
for (scanf("%d", &q); q; q--)
{
// if (q % 5000 == 0) cerr << q << endl;
int L, R;
tot++;
scanf("%d%d", &L, &R);
int ans = 0;
for (int i = L - 1; i <= R; i++)
{
if (lb[a[i]] != tot)
{
lb[a[i]] = tot;
l[a[i]] = i;
}
ans = max(ans, i - l[a[i]]);
}
printf("%d\n", ans);
}*/
/*for (int i = 0; i <= n; i++)
{
if (lb[a[i]] == 0)
{
lb[a[i]] = 1;
l[a[i]] = i;
d[i] = n + 1;
}
else
{
r[l[a[i]]] = i;
d[i] = i - l[a[i]];
l[a[i]] = i;
}
}
root[0] = build(1, n);
for (int i = 1; i <= n; i++)
{
if (r[i-1] != 0) root[i] = change(root[i - 1], 1, n, r[i-1]);
else root[i] = root[i - 1];
}
int q;
for (scanf("%d", &q); q; q--)
{
int L, R;
scanf("%d%d", &L, &R);
L--;
int ans = n + 1;
check(root[L], 1, n, R, ans);
if (ans == n + 1) printf("-1\n"); else printf("%d\n", ans);
}*/
/* int q;
int tans = 0;
for (scanf("%d", &q); q; q--)
{
int L, R;
scanf("%d%d", &L, &R);
L--;
tot++;
int ans = n + 1;
for (int i = L; i <= R; i++)
{
if (lb[a[i]] != tot)
{
lb[a[i]] = tot;
l[a[i]] = i;
}
else
{
ans = min(ans, i - l[a[i]]);
l[a[i]] = i;
}
}
if (ans == n + 1) printf("-1\n"); else {
printf("%d\n", ans);
tans = max(tans, ans);
}
}
cerr << clock()-ti << " "<<tans<<" "<<A<<" "<<B<<endl;*/
return ;
}

std

清北考前刷题day6下午好的更多相关文章

  1. 清北考前刷题day1下午好

    水题(water) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK出了道水题. 这个水题是这样的:有两副牌,每副牌都有n张. 对于第一副牌的每张牌长和宽 ...

  2. 清北考前刷题da7下午好

    三向城 /* 原图一定是一棵完全二叉树. 根节点是x,左节点是x*2,右节点是x*2+1 转化为二进制往左右走就很明显了. */ #include<iostream> #include&l ...

  3. 清北考前刷题day3下午好

    /* 可以并查集维护 可以发现,某个联通快出现大于等于2个环,一定无法分配. 有解要么一个环,要么没有环. 一个环时答案等于点数乘2(顺时针或逆时针). 没有环是树,对于一个n个点的树,方案一定有n种 ...

  4. 清北考前刷题da5下午好

    /* (4,1)*(3,1)*(2,1)的话1变成2然后一直是2 2变成1然后变成3 3变成1然后变成4 4变成1 */ #include<iostream> #include<cs ...

  5. 清北考前刷题day4下午好

    /* 辗转相除,每次计算多出现了几个数. */ #include<iostream> #include<cstdio> #include<cstring> #inc ...

  6. 清北考前刷题day2下午好

    #include<iostream> #include<cstdio> #include<cstring> #include<stack> #defin ...

  7. 清北考前刷题day6早安

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...

  8. 清北考前刷题day4早安

      LI /* 没有考虑次大值有大于一个的情况 */ #include<iostream> #include<cstdio> #include<cstring> # ...

  9. 清北考前刷题day7早安

随机推荐

  1. BNUOJ 26228 Juggler

    Juggler Time Limit: 3000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 42 ...

  2. 全文搜索(A-5)-推荐算法

    基于内容的推荐算法: 协同过滤推荐算法: 混合推荐算法: 基于内容的推荐算法做了如下假设:用户会喜欢和原来喜欢的物品相类似的项目.

  3. noip模拟赛 区间

    分析:要遍历所有的区间,肯定是枚举左端点,然后再枚举右端点.关键是怎么高效地求区间&,|,一般而言是用前缀和的,但是&,|不满足区间可减性,所以可以考虑线段树?这道题不带修改操作,用线 ...

  4. java中使用Protobuf的实例(Demo)

    由于Protobuf受到推崇,故尝试采用protobuf来摒弃传统的xml进行传输数据. 首先,需要下载的关于Protobuf的文件: 1.到http://code.google.com/p/prot ...

  5. 选学霸(codevs 3372)

    题目描述 Description 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一部分没有,同学们就会抗议.所以老师想请你帮他求出他该选多少学霸,才能既不让同 ...

  6. JSP内置对象和EL内置对象

    JSP共有九大内置对象: (1) HttpSession类的session对象作用:主要用于来分别保存每个用户信息,与请求关联的会话:         会话状态维持是Web应用开发者必须面对的问题. ...

  7. The Java library for converting Wikipedia wikitext notation to HTML

    https://code.google.com/p/gwtwiki/ The Java Wikipedia API (Bliki engine) is a parser library for con ...

  8. n个点中求任意两点组成斜率的最大值

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100 首先按x坐标排序,然后相邻的三个点A,B,C 组成的三条直线必然有 ...

  9. request详究

    本文主要是对在学习过程中遇到的request用法进行归纳总结,彻底的搞明白request在jsp中的作用. 百度百科的介绍如下: Request对象的作用是与客户端交互,收集客户端的Form.Cook ...

  10. Ubuntu 16.04中iptables的工具简介(iptables/iptables-restore/iptables-xml/iptables-apply/iptables-save)

    Ubuntu 16.04中安装的iptables版本为1.6.0,官方参考:http://www.linuxfromscratch.org/blfs/view/cvs/postlfs/iptables ...