Pagini recente » Cod sursa (job #2063414) | Cod sursa (job #745059) | Cod sursa (job #1355284) | Cod sursa (job #1752798) | Cod sursa (job #1089386)
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
ifstream f("shop.in");
ofstream g("shop.out");
unsigned long long n,c,l,aux,folosite = 0;
unsigned long rez[32];
struct monede
{
long long val;
unsigned long count;
int poz;
};
monede mon[31];
bool cmp (monede a, monede b) {return a.val > b.val; }
int main()
{
f >> n >> c >> l ;
for (int i=1;i<=n;i++)
{
unsigned long a,b;
f >> a >> b;
mon[i].count = b;
mon[i].val = pow(c,a);
mon[i].poz = i;
}
sort(mon+1,mon+n+1,cmp);
int k=1;
while (aux < l)
{
for (int j=1;j<=mon[k].count ;j++ )
{
aux += mon[k].val;
folosite++;
rez[mon[k].poz] ++;
if (aux + mon[k].val > l) break;
}
k++;
}
g << folosite << "\n";
for (int i=1;i<=n;i++)
if (rez[i]) g << rez[i] << " ";
return 0;
}