Cod sursa(job #523175)
#include<fstream>
#include<algorithm>
#define NMAX 32
using namespace std;
struct shop
{
int x, y, o;
long long p, v;
}a[NMAX];
int i, n;
long long c, L;
ifstream f("shop.in");
ofstream g("shop.out");
struct cmp
{
bool operator() (shop q, shop w)
{
if (q.x<w.x) return 1; return 0;
}
};
struct cmp2
{
bool operator() (shop q, shop w)
{
if (q.o<w.o) return 1; return 0;
}
};
void citeste()
{
int i;
f>>n>>c>>L;
for (i=1; i<=n; ++i) {f>>a[i].x>>a[i].y; a[i].o=i;}
sort(a+1, a+n+1, cmp());
}
long long putere(int m)
{
int pp=1;
while(m--) pp*=c;
return pp;
}
inline int minim(long long x, long long y)
{
return x<y ? x : y;
}
void solve()
{
int p=1, i, j=1, sum=0;
for (i=1; i<=n; ++i) a[i].p=putere(a[i].x);
for (i=n; i>0; --i)
{
a[i].v=minim(a[i].y, L/a[i].p);
L-=a[i].p*a[i].v; sum+=a[i].v;
}
g<<sum<<"\n";
sort(a+1, a+n+1, cmp2());
for (i=1; i<=n; ++i)
g<<a[i].v<<" ";
}
int main()
{
citeste();
solve();
f.close();
g.close();
return 0;
}