Pagini recente » Cod sursa (job #2044194) | Cod sursa (job #922323) | Cod sursa (job #915065) | Cod sursa (job #1091473) | Cod sursa (job #2136127)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("shop.in");
ofstream fout("shop.out");
struct shop{
int ai, bi, tip;
}v[35];
inline bool cmp(shop x, shop y){
return x.ai > y.ai;
}
long long putere[35];
int cnt[35];
void precalculare(long long baza, long long l){
short i = 2;
putere[0] = 1;
putere[1] = baza;
while(1){
putere[i] = putere[i - 1] * baza;
if(putere[i] >= l)
break;
++i;
}
}
int main()
{
long long n, c, l;
fin >> n >> c >> l;
for(int i = 1; i <= n; ++i){
fin >> v[i].ai >> v[i].bi;
v[i].tip = i;
}
sort(v + 1, v + n + 1, cmp);
precalculare(c, l);
int sum = 0;
for(int i = 1; i <= n; ++i){
if(putere[v[i].ai]){
long long times = l / putere[v[i].ai];
if(times >= v[i].bi){
l -= (putere[v[i].ai] * v[i].bi);
cnt[v[i].tip] = v[i].bi;
}
else {
l -= (putere[v[i].ai] * times);
cnt[v[i].tip] = times;
}
sum += cnt[v[i].tip];
}
}
fout << sum << '\n';
for(int i = 1; i <= n; ++i)
fout << cnt[i] << ' ';
fout << '\n';
return 0;
}