Pagini recente » Cod sursa (job #2901505) | Cod sursa (job #2650420) | Cod sursa (job #791913) | Cod sursa (job #853021) | Cod sursa (job #790604)
Cod sursa(job #790604)
using namespace std;
#include<vector>
#include<queue>
#include<cstdio>
#define nmax 6000003
#define inf 2000000000
#define pq priority_queue
#define p pair<int,int>
struct Qcomp
{
bool operator()(const p&a,const p&b)const
{
return a.second>b.second;
}
};
int main ()
{
vector<int>v(nmax),best(nmax);
pq<p,vector<p>,Qcomp >heap;
long int n,i,maxsum=-inf,x,y,s;
FILE *f=fopen("ssm.in","r");
FILE *g=fopen("ssm.out","w");
fscanf(f,"%ld",&n);
best[0]=0;
for(i=1;i<=n;i++)
fscanf(f,"%d",&v[i]),best[i]=v[i]+best[i-1];
heap.push(make_pair(1,best[1]));
for(i=2;i<=n;i++)
{
s=best[i]-heap.top().second;
if(s>v[i])
best[i]=s;
else
best[i]=v[i];
heap.push(make_pair(i,best[i]));
if(maxsum<best[i])
maxsum=best[i],x=heap.top().first+1,y=i;
}
fprintf(g,"%ld %ld %ld",maxsum,x,y);
fclose(f);
fclose(g);
return 0;
}