Pagini recente » Cod sursa (job #1214823) | Cod sursa (job #2766278) | Cod sursa (job #2167972) | Cod sursa (job #55692) | Cod sursa (job #1295308)
#include <fstream>
#include <algorithm>
#define LL long long
using namespace std;
ifstream fin ("shop.in");
ofstream fout ("shop.out");
struct art { LL a, b, c; };
LL N, C, L, s, Sol[40];
art V[40];
bool cmp(art x, art y)
{
return (x.a < y.a);
}
LL Lg_Put(LL nr, LL p)
{
LL val = 1;
while (p)
{
if (p & 1) val = val * nr;
nr = nr * nr;
p = (p >> 1);
}
return val;
}
int main()
{
fin >> N >> C >> L;
for (int i=1; i<=N; i++)
{
fin >> V[i].a >> V[i].b;
V[i].c = i;
}
sort (V + 1, V + 1 + N, cmp);
LL l = 0, nr = N;
while (l < L)
{
LL p = V[nr].b;
LL x = Lg_Put(C, V[nr].a);
while (l + x * p > L)
{
p--;
}
l += x * p;
Sol[V[nr].c] = p;
s += p;
nr--;
}
fout << s << '\n';
for (LL i=1; i<=N; i++) fout << Sol[i] << ' ';
fout.close();
return 0;
}