Cod sursa(job #1295306)

Utilizator EpictetStamatin Cristian Epictet Data 19 decembrie 2014 10:25:26
Problema Shop Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <algorithm>
#define LL long long
using namespace std;
ifstream fin ("shop.in");
ofstream fout ("shop.out");
struct art { LL a, b, c; };
LL N, C, L, s, Sol[40];
art V[40];

bool cmp(art x, art y)
{
    return (x.a < y.a);
}

LL Lg_Put(LL nr, LL p)
{
    LL val = 1;
    while (p)
    {
        if (p & 1) val = val * nr;
        nr = nr * nr;
        p = (p >> 1);
    }
    return val;
}

int main()
{
    fin >> N >> C >> L;
    for (LL i=1; i<=N; i++)
    {
        fin >> V[i].a >> V[i].b;
        V[i].c = i;
    }
    sort (V + 1, V + 1 + N, cmp);

    LL l = 0, nr = N;
    while (l < L)
    {
        LL p = V[nr].b;
        while (l + Lg_Put(C, V[nr].a) * p > L)
        {
            p--;
        }
        l += Lg_Put(C, V[nr].a) * p;
        Sol[V[nr].c] = p;
        s += p;
        nr--;
    }

    fout << s << '\n';
    for (LL i=1; i<=N; i++) fout << Sol[i] << ' ';
    fout.close();
    return 0;
}