Cod sursa(job #902371)

Utilizator paul.chPaul Chelarescu paul.ch Data 1 martie 2013 13:50:33
Problema Farfurii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 3.36 kb
#include <fstream>
using namespace std;
int n, timp, quiveta[1010], farf[10100], timp_total, g, d, solutie_vase, solutie_timp;
short spart[10100];
ifstream fin ("farfurii.in");
ofstream fout("farfurii.out");
inline void citire()
{
    fin >> n >> timp;
    for(int a = 1; a <= n; ++a)
    {
        fin >> quiveta[a];
    }
}
//inline void prel2(int c, bool ok, int okk, int timp_total, int last)
//{
//    if(c <= n)
//    {
//        if(timp_total <= timp)
////            if(!(last >= solutie_timp and farf[last] <= solutie_vase))
//            {
////                for(d = timp ; d >= 1; --d and ok)
//                d = last;
////                while(d >= 1 and ok)
//                {
//                    if(farf[d] /*and ok*/)
//                    {
//                        if(farf[d] > solutie_vase /*and d < solutie_timp*/)
//                        {
//                            solutie_vase = farf[d];
//                            solutie_timp = d;
//                        }
//                        if(farf[d] == solutie_vase and d < solutie_timp)
//                        {
//                            solutie_vase = farf[d];
//                            solutie_timp = d;
//                        }
//                        if(d + quiveta[c] <= timp /*and farf[d] + 1 > farf[d + quiveta[c] ]*/)
//                        {
//                            farf[d + quiveta[c] ] = farf[d] + 1;
//                            if(timp_total <= timp)prel2(c + 1, true, 0, timp_total + quiveta[c], d + quiveta[c]);
//                            okk = 1;
//                            farf[d + quiveta[c] ]  =0;
//                        }
//                        if(d + 1 <= timp /*and farf[d] > farf[d + 1]*/)
//                        {
//                            farf[d + 1] = farf[d] + 0;
//                            if(timp_total <= timp)prel2(c + 1, true, 0, timp_total + 1, d + 1);
//                            okk = 1;
//                            farf[d + 1] = 0;
//                        }
//                        ok = false;
//                    }
//                    --d;
//                }
//
//            }
//    }
//}
inline int cauta(int d)
{
    int maxi = 0;
    int ex;
    for(int r = 1; r < d; ++r)
    {
        if(quiveta[r] > quiveta[maxi] ) maxi = r;
    }
    ex = quiveta[maxi];
    quiveta[maxi] = 0;
    return ex;
}
inline void prel3()
{
    int biggest;
    int vase = 0;
    d = 1;
    while(d <= n)
    {
        timp_total += quiveta[d];
        ++vase;
        ++d;
        if(timp_total > timp)
        {
            biggest = cauta(d);
            timp_total -= biggest;
            timp_total ++;
            --vase;
        }
        if(vase > solutie_vase)
        {
            solutie_vase  = vase;
            solutie_timp = timp_total;
        }
        if(vase == solutie_vase and timp_total < solutie_timp)
        {
            solutie_timp = timp_total;
        }
    }
}
int main()
{
    solutie_timp = 60000;

    citire();
    prel3();
//    g = 2;
//    solutie_vase = 0;
//    farf[quiveta[1]] = 1;
//    prel2(g, true, 0, quiveta[1], quiveta[1]);
//    farf[quiveta[1]] = 0;
//    farf[quiveta[2] + 1] = 1;
//    prel2(2, true, 0, quiveta[2] + 1, quiveta[2] + 1);
    fout << solutie_vase << " " << solutie_timp;
    return 0;
}