Cod sursa(job #2136344)

Utilizator adiaioanaAdia R. adiaioana Data 19 februarie 2018 20:47:42
Problema Shop Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("shop.in");
ofstream fout("shop.out");
unsigned long long v[55],l,c,s;
int w[50],p,n,d;
struct chestie{
    int val,ind,nr;
}a[50];
void powerc();
bool comp(chestie a,chestie b);
int main()
{
    fin>>n>>c>>l;
    powerc();
    for(int i=1;i<=n;i++)
    {
        fin>>p>>a[i].nr;
        a[i].val=v[p];
        a[i].ind=i;
    }
    sort(a+1,a+n+1,comp);
    for(int i=1;i<=n&&l;i++)
    {
        d=l/a[i].val;
        w[a[i].ind]=min(d,a[i].nr);
        s+=w[a[i].ind];
        l=l-(min(d,a[i].nr)*a[i].val);
    }
    fout<<s<<'\n';
    for(int i=1;i<=n;i++)
        fout<<w[i]<<' ';
    return 0;
}
bool comp(chestie a,chestie b)
{
    return (a.val>b.val);
}
void powerc()
{
    v[0]=1;
    for(int i=1;v[i-1]*c<=l;i++)
        v[i]=v[i-1]*c;
}