Pagini recente » Istoria paginii runda/redsnow_4 | Cod sursa (job #1896566) | Cod sursa (job #1721146) | Cod sursa (job #2719640) | Cod sursa (job #1216950)
#include <fstream>
#include <algorithm>
#define ll long long
using namespace std;
ifstream f("shop.in");
ofstream g("shop.out");
struct moneda{ int x, y, z; } A[32];
ll N, c, used[32], sol, L;
bool cmp(moneda a, moneda b) { return a.x>b.x; }
ll pow(int baza, int exp)
{
ll rez=1;
while (exp)
{
if (exp%2) rez*=baza;
exp/=2; baza*=baza;
}
return rez;
}
int main()
{
f>>N>>c>>L;
for (int i=1; i<=N; ++i)
f>>A[i].x>>A[i].y, A[i].z=i;
sort(A+1, A+N+1, cmp);
for (int i=1; i<=N; ++i)
{
ll x=pow(c, A[i].x);
while (A[i].y && L-x>=0)
++sol, L-=x, ++used[A[i].z], --A[i].y;
}
g<<sol<<'\n';
for (int i=1; i<=N; ++i)
g<<used[i]<<' ';
return 0;
}