Pagini recente » Cod sursa (job #2870675) | Cod sursa (job #1908460) | Cod sursa (job #1310954) | Cod sursa (job #631932) | Cod sursa (job #2473998)
#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;
}