Cod sursa(job #3347516)

Utilizator Gabriel_DaescuDaescu Gabriel Florin Gabriel_Daescu Data 17 martie 2026 08:32:48
Problema SequenceQuery Scor 65
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#define NMAX 100005
#define INF (-1LL<<60)
using namespace std;
ifstream  fin("sequencequery.in");
ofstream fout("sequencequery.out");
int N,M,v[NMAX];

void citire()
{
    fin>>N>>M;

    for(int i=1; i<=N; i++)
    {
        fin>>v[i];
    }
}


int main()
{
    citire();

    int x,y;
    for(int q=1; q<=M; q++)
    {
        fin>>x>>y;

        long long smax,s;
        smax=s=INF;
        for(int i=x; i<=y; i++)
        {
            if(s+v[i]>v[i])
            {
                s+=v[i];
            }
            else
            {
                s=v[i];
            }
            smax=max(smax,s);
        }

        fout<< smax << "\n";
    }

    return 0;
}