Cod sursa(job #1328679)

Utilizator dr_personalityEftime Andrei Horatiu dr_personality Data 28 ianuarie 2015 17:44:20
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("shop.in");
ofstream out("shop.out");

struct shop{
    long long a, b, poz;
};

const int nmax = 36;
long long p, k, n, aux, s, act, chestie, vrasp[nmax], rasp;
shop v[nmax];

int compar(shop a, shop b){
    return a.a>b.a;
}

int main()
{
	int player_unu=0;

    in>>n>>k>>s;
    for(int i = 1; i<=n; i++)
	{
        in>>v[i].a>>v[i].b;

        v[i].poz = i;
    }

    sort(v + 1, v + n + 1, compar);

    p = 1;
    for(int i = 1; i<=v[1].a; i++)
        p *= k;
    act = 1;
    aux = v[1].a;
 
    while(s>0)
	{
        chestie = 0;
        while(v[act].b>0 && p<=s)
		{
            v[act].b--;
            s -= p;
            ++chestie;
        }

        rasp += chestie;
        vrasp[v[act].poz] = chestie;
        act++;

        for(int i = aux; i>v[act].a; i--)
		{
            p /= k;
			aux = i;
		}
        aux--;
    }

    out<<rasp<<'\n';
    for(int i = 1; i<=n; i++)
        out<<vrasp[i]<<' ';

    return player_unu;
}