Pagini recente » Cod sursa (job #622527) | Cod sursa (job #888867) | Cod sursa (job #203802) | Cod sursa (job #1911494) | Cod sursa (job #790593)
Cod sursa(job #790593)
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;
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[i]));
for(i=2;i<=n;i++)
{
best[i]=best[i]-heap.top().second;
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;
}