Pagini recente » Cod sursa (job #1118376) | Cod sursa (job #1564529) | Cod sursa (job #2030873) | Cod sursa (job #392812) | Cod sursa (job #248151)
Cod sursa(job #248151)
//STUPID
#include<cstdio>
#include<algorithm>
using namespace std;
#define NMAX 32
pair< long long, int > A[NMAX];
long long SOL[NMAX];
int I[NMAX];
inline bool cmp(const int a,const int b)
{
return A[a].first > A[b].first;
}
long long power(long long a,long long b)
{
if(b == 1)
return a;
else
{
if( b%2 )
return power(a,b/2) * power(a,b/2)*a;
else
return power(a,b/2) * power(a,b/2);
}
}
int main()
{
freopen("shop.in","r",stdin);
freopen("shop.out","w",stdout);
long long N,C,ANS=0;
long long L;
scanf("%lld%lld%lld\n",&N,&C,&L);
long long i,a1,a2;
for(i=1; i<=N; ++i)
{
scanf("%lld%lld\n",&a1,&a2);
if( a1 )
A[i].first=power(C,a1);
else
A[i].first=1;
A[i].second=a2;
I[i]=i;
}
sort( I+1, I+1+N, cmp );
i=1;
long long MIN;
while( L && i<=N )
{
a1=I[i];
if( A[a1].first > L )
{ ++i; continue;}
a2=(L/A[a1].first);
MIN=a2<A[a1].second?a2:A[a1].second;
L-=MIN*A[a1].first;ANS+=MIN; SOL[ a1 ]+=MIN;
++i;
}
printf("%lld\n",ANS);
for(i=1; i<=N; ++i)
printf("%lld ",SOL[i]);
printf("\n");
return 0;
}