Pagini recente » Cod sursa (job #1509056) | Cod sursa (job #151021) | Cod sursa (job #1128044) | Cod sursa (job #370913) | Cod sursa (job #1295306)
#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 (LL 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;
while (l + Lg_Put(C, V[nr].a) * p > L)
{
p--;
}
l += Lg_Put(C, V[nr].a) * 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;
}