Cod sursa(job #1242841)

Utilizator andreismara97Smarandoiu Andrei andreismara97 Data 15 octombrie 2014 08:44:17
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream in("shop.in");
ofstream out("shop.out");

struct sho{ int x,y,ct,val; };
sho v[32];

bool comp(sho i,sho j)
{
    return i.x>j.x;
}

long long poww(int baz,int p)
{
    long long aux=1;
    for(int i=1;i<=p;i++)
        aux*=baz;
    return aux;
}

bool compp(sho i,sho j)
{
    return i.ct<j.ct;
}

int main ()
{
    long long n,c,t;
    long long nr,suma=0;
    in>>n>>c>>t;
    for(int i=1;i<=n;i++)
    {
        in>>v[i].x>>v[i].y;
        v[i].ct=i;
        v[i].val=0;
    }
    sort(v+1,v+n+1,comp);
    int aux;
    for(int i=1;i<=n;i++)
    {
        nr=poww(c,v[i].x);
        if(nr*v[i].y<=t)
        {
            t-=nr*v[i].y;
            v[i].val+=v[i].y;
            suma+=v[i].y;
        }
        else
        {
            aux=t/nr;
            t-=nr*aux;
            v[i].val+=aux;
            suma+=aux;
        }
    }
    sort(v+1,v+n+1,compp);
    out<<suma<<'\n';
    for(int i=1;i<=n;i++)
        out<<v[i].val<<' ';
    return 0;
}