Cod sursa(job #736172)

Utilizator alex_unixPetenchea Alexandru alex_unix Data 17 aprilie 2012 23:52:42
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb

#include <fstream>

const unsigned short SIZE(1000);

char camere [SIZE];
char trash [SIZE << 1];

int main (void)
{
    unsigned short n,m;
    std::ifstream input("aprindere.in");
    input >> n >> m;
    char *it(camere),*limit(camere + n);
    do
    {
        input >> *it;
        ++it;
    }
    while (it < limit);
    unsigned short t,nrc;
    unsigned int cost(0);
    do
    {
        input >> n >> t >> nrc;
        if (camere[n] == '0')
        {
            cost += t;
            do
            {
                input >> n;
                if (camere[n] == '1')
                    camere[n] = '0';
                else
                    camere[n] = '1';
                --nrc;
            }
            while (nrc);
        }
        else
            input.getline(trash,SIZE << 1);
        --m;
    }
    while (m);
    input.close();
    std::ofstream output("aprindere.out");
    output << cost << '\n';
    output.close();
    return 0;
}