CodeForces 740B Alyona and flowers

前缀和。

把区间和为正的都选了即可。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c = getchar();
    x = 0;
    while(!isdigit(c)) c = getchar();
    while(isdigit(c))
    {
        x = x * 10 + c - '0';
        c = getchar();
    }
}

int a[200];
int n,m;
int b[200];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) cin>>a[i],a[i]+=a[i-1];
    for(int i=1;i<=m;i++)
    {
        int L,R; cin>>L>>R;
        b[i]=a[R]-a[L-1];
    }
    int sum=0;
    for(int i=1;i<=m;i++) if(b[i]>0) sum+=b[i];
    cout<<sum;

    return 0;
}

 

posted @ 2017-02-14 12:30  Fighting_Heart  阅读(167)  评论(0编辑  收藏  举报