Cod sursa(job #1513058)

Utilizator matzuu000FMI Mihai Bogdan matzuu000 Data 28 octombrie 2015 22:28:04
Problema Cuburi2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <iostream>
#include <fstream>
using namespace std;
void mutare (int x, int y,int v[100])
{


    return;
}

int main()
{
    int n,m,i,j,x,y,v[100],sumaM,suma2,pivot,pasi;
    ifstream f("cuburi2.in");
    ofstream g("cuburi2.out");
    f>>n>>m;
    for (i=1;i<=n;i++)
        {
            f>>v[i];
        }
    for (i=0;i<m;i++)
        {
            f>>x>>y;
            suma2=0;
            sumaM=0;
            pasi=0;

            for (j=x;j<=y;j++)
            {
                sumaM=sumaM + v[j];
            }
            j=x;
            while (suma2<sumaM/2)
            {
                suma2 = suma2 + v[j];
                j++;
            }
            if (j>y)
                pivot=j-1;
            else
                if ((suma2-sumaM/2)>(sumaM/2+v[j]-suma2))
                    pivot=j-1;
                else pivot=j;
            for (j=x;j<pivot;j++)
            {
                pasi = pasi + v[j]*(pivot-j);
            }
            for (j=pivot+1;j<=y;j++)
            {
                pasi = pasi + v[j]*(j-pivot);
            }
            g<<pivot<<" "<<pasi<<endl;
        }
    g.close();
    return 0;
}