Cod sursa(job #2473998)

Utilizator IoanMihaiIoan Mihai IoanMihai Data 14 octombrie 2019 16:37:31
Problema SequenceQuery Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sequencequery.in");
ofstream fout("sequencequery.out");
int smax,n,m,x,y,a[100005],best[100005];
#define MIN -10000000
int main()
{
    fin >> n >> m;
    for (int i=1;i<=n;i++)
    {
        fin >> a[i];
    }
    for (int j=1;j<=m;j++)
    {
        fin >> x >> y;
        best[x-1] = 0;
        smax = MIN;
        for (int i=x;i<=y;i++)
        {
            best[i] = a[i];
            if (best[i-1]+a[i]>best[i])
                best[i] = best[i-1] + best[i];
            if (best[i]>smax)
                smax = best[i];
        }
        fout << smax << '\n';
    }
    return 0;
}