/*
贪心 负数一定不取
枚举最高位是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. About SQL Server 2014 SP1

    其实补丁这个月初就放出,个人懒惰所以也没怎么写归整文档 官方Blog: http://blogs.technet.com/b/dataplatforminsider/archive/2015/05/1 ...

  2. 解决在使用Amoeba遇到的问题

    最近有同行在使用Amoeba 的过程中多少遇到了一些问题. 总结一下遇到问题的解决方法: 1.读写分离的时候设置的在queryRouter中设置无效? 读写分离配置的优先级别:        1)满足 ...

  3. [luoguP1037] 产生数(floyd + 高精度)

    传送门 先用 floyd 求出每一个数可以变成那些数. 然后利用乘法原理求解,需要高精度. 代码 #include <cstdio> #include <cstring> #i ...

  4. [K/3Cloud] 理解BOS关于Enabled属性的表决器原理

    通常的编程中,我们习惯: btnOK.Enabled = true; 这个样子就会将按钮变成有效,反之亦然.但在ERP的表单中,其某个按钮或字段其有效性及其复杂,例如一个表格中某个数量单元格其有效性是 ...

  5. SOJ 4454 (矩阵快速幂)

    先引入数的快速幂 例如计算2的5次方,常规算法2*2*2*2*2,利用快速幂的思想,求出5的二进制表达式101,权值为1和4的位上数字为1,即2^5=2^1*2^4.代码如下,时间复杂度为O(logn ...

  6. poj —— 1274 The Perfect Stall

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26274   Accepted: 116 ...

  7. CDOJ1339 郭大侠与线上游戏(维护一个set中的中位数——平衡树/双set)

    http://acm.uestc.edu.cn/#/problem/show/1339 题意:有三种操作,分别是. 1.向队列推入一个数x. 2.弹出这个队列的第一个数字 3.查询这个队列的中位数是多 ...

  8. 洛谷 P1608 路径统计

    P1608 路径统计 题目描述 “RP餐厅”的员工素质就是不一般,在齐刷刷的算出同一个电话号码之后,就准备让HZH,TZY去送快餐了,他们将自己居住的城市画了一张地图,已知在他们的地图上,有N个地方, ...

  9. ssh forwarding 配置

    假设有服务器A,属于某一内网,无法直接登录. A: 10.0.1.48 root/password@a 但我们有一台跳板机器可以访问该Server A B: 10.0.2.48 root/passwo ...

  10. json序列化后的是字符串,不是二进制。是字符串!!!确定不是二进制!!!

    1.现有一个自定义对象需要储存到sql数据库中去.这个对象里面属性很多,甚至包含一些元素量打到几十万的List集合属性.本人试着使用JSON序列化这个对象,储存到数据库,报maxjsonlength超 ...