Cod sursa(job #1389208)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 16 martie 2015 09:02:45
Problema Shop Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <cstdio>
int n,c;
long long b[45],p[45],fol[45];
int arr[33];
long long l;
void desc(long long nr)
{
     
     int pos=0;
     while(nr!=0)
     {
                 b[pos]=nr%c;
                 nr/=c;      
                 pos++;     
     }
}
int main()
{
    FILE *fin;
    fin=fopen ("shop.in","r");
    freopen ("shop.out","w",stdout);
    fscanf(fin,"%d%d%lld",&n,&c,&l);
    long long int bx;
    for(int i=1;i<=n;i++)
    {
            fscanf(fin,"%d%lld",&arr[i],&bx);
            p[arr[i]]=bx;
    }
    desc(l);
    for(int i=32;i>=0;i--)
    {
            if(b[i]!=0)
            {
                       if(b[i]>=p[i])
                       {
                                    b[i]-=p[i];
                                    fol[i]+=p[i];
                                    if(i!=0) b[i-1]+=c*b[i];
                       }
                       else
                       {
                           fol[i]=b[i];
                           b[i]=0;
                       }
            }
    }
    int sum=0;
    for(int i=0;i<=32;i++) sum+=fol[i];
    printf("%d\n",sum);
    for(int i=1;i<=n;i++)
    {
            printf("%lld ",fol[arr[i]]);
    }
    fclose(fin);
}