Cod sursa(job #932795)

Utilizator crisbodnarCristian Bodnar crisbodnar Data 29 martie 2013 11:38:11
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("shop.in");
ofstream fout("shop.out");

long long n, c, l, sum, nrm, used[32];

struct mon{
    long long val, m, poz;
}monede[32];

bool cmp(mon a, mon b){
    return a.val > b.val;
}

long long Putere(long long a){
    long long x = 1;
    for(int i=1; i<=a; i++)
        x *= c;
    return x;
}

int main()
{
    fin>>n>>c>>l;
    for(int i=1; i<=n;i++){
        fin>>monede[i].val>>monede[i].m;
        monede[i].poz = i;
    }

    sort(monede + 1, monede + n + 1, cmp);

    for(int i=1; i<=n; i++){
        if(l == sum) break;

        long long nrmax = monede[i].m, x = Putere(monede[i].val);
        while(nrmax && sum <= l){
            sum += x;
            used[monede[i].poz]++;
            nrmax--;
            nrm++;
        }
        if(sum > l) sum -= x, nrm--, used[monede[i].poz]--;
    }

    fout<<nrm<<'\n';
    for(int i=1; i<=n;i++)
        fout<<used[i]<<" ";

    return 0;
}