Pagini recente » Cod sursa (job #2263985) | Cod sursa (job #2940772) | Cod sursa (job #3244640) | Cod sursa (job #2181097) | Cod sursa (job #1242372)
#include <fstream>
#include <cmath>
#include <iostream>
#include <algorithm>
typedef unsigned long long big;
using namespace std;
ifstream f("shop.in");
ofstream g("shop.out");
int N,C,R;
big L;
struct plata{
int poz;
big val;
big num;
};
plata A[31];
big REZ[31];
inline big putere(int p)
{
if (p == 0) return 1;
big temp = C;
for (int i=1; i<p ; i++)
temp *= C;
return temp;
}
int cmp(plata A, plata B)
{
return A.val>B.val;
}
int main()
{
f >> N >> C >> L ;
for (int i=1; i <= N ; i++)
{
int x,y;
f >> x >> y;
A[i].poz = i;
A[i].val = putere(x);
A[i].num = y;
}
sort(A+1,A+N+1,cmp);
int i = 1;
while (L)
{
big temp ;
temp = L / A[i].val;
temp = min(temp,A[i].num);
REZ[A[i].poz] = temp;
L -= A[i].val * temp;
R += temp;
i++;
}
g << R << '\n';
for (int i=1; i<= N ; i++)
if (REZ[i]) g << REZ[i] << ' ';
/*
for (int i=1; i <= N ; i++)
cout << A[i].val << " " << A[i].num << '\n';
*/
return 0;
}