Cod sursa(job #2210301)

Utilizator sonthesunson andreea sonthesun Data 6 iunie 2018 09:24:09
Problema Numarare triunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <fstream>

using namespace std;

ifstream in("xspe.in");
ofstream out("xspe.out");

int n,v[1000001],st[1000001],k;

int main()
{
    in>>n;
    for(int i=1; i<=n; i++) in>>v[i];
    k=1;
    st[k]=v[n];
    for(int i=n-1; i>=1; i--)
    {
    	while(k>=1 && v[i]<=st[k]) k--;
    	k++;
    	st[k]=v[i];
    	v[i]=v[i]+st[k-1];
    }
    for(int i=1; i<=n; i++) out<<v[i]<<" ";
    return 0;
}