http://codeforces.com/contest/353/problem/C

先预处理前i个数的和,然后找到第一个出现的1,然后变成0后的和与目前的和比较,如果大就更新。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100010
using namespace std; int n;
int a[maxn];
int sum[maxn];
char str[maxn];
int k; int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(sum,,sizeof(sum));
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
scanf("%s",str);
int ans=;
for(int i=; i<=n-; i++)
{
if(str[i]=='')
{
ans+=a[i+];
k=i;
}
}
int max1=ans;
int c=;
for(int i=k; i>; i--)
{
if(str[i]=='')
{
max1=max(max1,sum[i]+c);
c+=a[i+];
}
}
printf("%d\n",max1);
}
return ;
}

cf C. Find Maximum的更多相关文章

  1. cf#513 B. Maximum Sum of Digits

    B. Maximum Sum of Digits time limit per test 2 seconds memory limit per test 512 megabytes input sta ...

  2. CF 353C Find Maximum #205 (Div. 2)

    #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ]; ] ...

  3. CF#508 1038E Maximum Matching

    ---题面--- 题解: 感觉还是比较妙的,复杂度看上去很高(其实也很高),但是因为n只有100,所以还是可以过的. 考虑一个很暴力的状态f[i][j][x][y]表示考虑取区间i ~ j的方格,左右 ...

  4. [CF 1238F] The Maximum Subtree 树DP

    题意 给定一颗树,求这个树的最大子树,且这个子树是一个good-tree. good-tree的定义是:每个节点可以表示成一个数值区间,而树上的边表示两个点表示的数值区间相交. 题解 通过分析可以发现 ...

  5. CF problem: (D) Maximum Product Strikes Back

    Problem - D - Codeforces Example input 5 4 1 2 -1 2 3 1 1 -2 5 2 0 -2 2 -1 3 -2 -1 -1 3 -1 -2 -2 out ...

  6. CF 375B Maximum Submatrix 2[预处理 计数排序]

    B. Maximum Submatrix 2 time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

  7. 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

    A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...

  8. CF 276C Little Girl and Maximum Sum【贪心+差分】

    C. Little Girl and Maximum Sum time limit per test2 seconds memory limit per test256 megabytes input ...

  9. cf D. Maximum Submatrix 2

    http://codeforces.com/contest/376/problem/D 题意:给你一个矩阵,可以随意排列n行的次序,然后找出全部含有1的子矩阵.输出1的个数. 思路:c[i][j]表示 ...

随机推荐

  1. windows 查看文件被哪个进程占用

    经常当我们删除文件时,有时会提示[操作无法完成,因为文件已在另一个程序中打开,请关闭该文件并重试],到底是哪些程序呢? 有时候一个一个找真不是办法,已经被这个问题折磨很久了,今天下决心要把它解决,找到 ...

  2. Android中的ScrollView实现 拖拽反弹效果

    public class BounceScrollView extends ScrollView { private View inner;// 孩子View private float y;// 点 ...

  3. Android圆角矩形的实现

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:Android=&quo ...

  4. Android手势操作

    xml文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:to ...

  5. VMware migration to openstack kvm

  6. 如何断开eclipse与svn的链接

    右键点击需要断开的项目 Team-->Disconnect 如果想删除svn配置文件,选择Also delete the SVN meta information from the file s ...

  7. 关于数据表命名为mysql保留的时候的操作

    今天操作数据表的时候,发现order数据表无法进行操作,必须加上反单引号才能进行操作,查了一下原因: 反引号是用来区别mysql关键字的,比如,如果你有一个表名叫select,你就必须写成`selec ...

  8. lesson2:java阻塞队列的demo及源码分析

    本文向大家展示了java阻塞队列的使用场景.源码分析及特定场景下的使用方式.java的阻塞队列是jdk1.5之后在并发包中提供的一组队列,主要的使用场景是在需要使用生产者消费者模式时,用户不必再通过多 ...

  9. 添加链接服务器 SQL SERVER

    使用sql语句: exec sp_addlinkedserver @server='serverontest',@provider='sqloledb',@srvproduct='',@datasrc ...

  10. NSData的一些用法

    //NSData遵循NSCopying NSCoding协议,它提供面向对象的数组存储为字节 //适用与读写文件,而读写文件的时候需要一个缓冲区,而NSDate就提供了这么一个缓存区 //定义一个ch ...