Pagini recente » Cod sursa (job #659890) | Cod sursa (job #1528949) | Cod sursa (job #1122384) | Rating Maghiar Tudor (Tudor123456789) | Cod sursa (job #1520357)
#include <iostream>
#include <fstream>
#define NMAX 100005
#define INF 200005
using namespace std;
ifstream in("sequencequery.in");
ofstream out("sequencequery.out");
int n,a[NMAX],m,x,y;
int best[NMAX];
int din(int x, int y)
{
for(int i=0;i<=n;i++)
best[i]=0;
int Max =a[x];
best[x] = a[x];
for(int i=x+1;i<=y;i++)
{
best[i] = a[i];
if(best[i] < best[i-1]+a[i])
best[i] = best[i-1] + a[i];
if(Max <best[i])
Max = best[i];
}
return Max;
}
int main()
{
in >> n >> m;
for(int i=1;i<=n;i++)
in >> a[i];
for(int i=0;i<m;i++)
{
in >> x >> y;
out << din(x,y) << "\n";
}
return 0;
}