Cod sursa(job #1002501)

Utilizator Johny_Depp22Johnny Depp Johny_Depp22 Data 27 septembrie 2013 21:43:42
Problema Shop Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("shop.in");
ofstream g("shop.out");

struct moneda{ int x, y, z; } A[32];
int N, L, c, used[32], sol;
bool cmp(moneda a, moneda b) { return a.x>b.x; }

long long pow(int baza, int exp)
{
    long long rez=1;
    while (exp)
    {
        if (exp%2) rez*=baza;
        exp/=2; baza*=baza;
    }
    return rez;
}

int main()
{
    f>>N>>c>>L;
    for (int i=1; i<=N; ++i)
        f>>A[i].x>>A[i].y, A[i].z=i;

    sort(A+1, A+N+1, cmp);

    for (int i=1; i<=N; ++i)
    {
        while (A[i].y && L-pow(c, A[i].x)>=0)
            ++sol, L-=pow(c, A[i].x), ++used[A[i].z], --A[i].y;
    }

    g<<sol<<'\n';
    for (int i=1; i<=N; ++i)
        g<<used[i]<<' ';

    return 0;
}