Cod sursa(job #1058665)

Utilizator andreiiiiPopa Andrei andreiiii Data 15 decembrie 2013 19:20:19
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <algorithm>
#include <fstream>

using namespace std;

const int N=35;

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

struct nr
{
    int poz, y;
    long long x, sol;
};

nr a[N];

long long pw(long long x, int y)
{
    long long ret;
    for(ret=1;y;y>>=1)
    {
        if(y&1) ret*=x;
        x*=x;
    }
    return ret;
}

bool comp1(nr r, nr t) {return r.x>t.x;}
bool comp2(nr r, nr t) {return r.poz<t.poz;}

int main()
{
    int n, C, i, sol=0;
    long long L;
    fin>>n>>C>>L;
    for(i=1;i<=n;i++)
    {
        fin>>a[i].x>>a[i].y;
        a[i].x=pw(C, a[i].x);
        a[i].poz=i;
    }
    fin.close();
    sort(a+1, a+n+1, comp1);
    for(i=1;i<=n&&L;i++)
    {
        a[i].sol=min(1LL*a[i].y, L/a[i].x);
        L-=a[i].sol*a[i].x;
        sol+=a[i].sol;
    }
    fout<<sol<<"\n";
    sort(a+1, a+n+1, comp2);
    for(i=1;i<=n;i++)
    {
        fout<<a[i].sol<<" ";
    }
}