Cod sursa(job #1174698)

Utilizator horatiu11Ilie Ovidiu Horatiu horatiu11 Data 23 aprilie 2014 18:25:19
Problema Shop Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
//horatiu11
# include <cstdio>
# include <algorithm>
using namespace std;
int n,c,t,a,y[101],z[101];
long long l;
struct monezi{long long v;int buc,nr;}x[101];
bool cmp(monezi a, monezi b)
{
    return a.v>b.v;
}
int main()
{
    int i,j;
    freopen("shop.in","r",stdin);
    freopen("shop.out","w",stdout);
    scanf("%d%d%lld",&n,&c,&l);
    for(i=1;i<=n;++i)
    {
        scanf("%d%d",&a,&x[i].buc);
        x[i].nr=i;x[i].v=1;
        for(j=1;j<=a;++j)
            x[i].v*=c;
    }
    sort(x+1,x+n+1,cmp);i=1;
    while(l>0)
    {   c=l/x[i].v;
        y[i]=min(c,x[i].buc);
        z[i]=x[i].nr;
        l=l-y[i]*x[i].v;
        t+=y[i];
        i++;
    }
    printf("%d\n",t);
    for(i=1; i<=n; i++)
    {   j=1;
        while(z[j]!=i) j++;
        printf("%d ",y[j]);
    }
    printf("\n");return 0;
    return 0;
}