Pagini recente » Cod sursa (job #1159085) | Cod sursa (job #2451918) | Cod sursa (job #221596) | Cod sursa (job #215083) | Cod sursa (job #1366514)
#include <fstream>
#include <algorithm>
using namespace std;
struct el
{
int x,y,poz,b;
};
el v[32];
bool cmp(el a,el b)
{
if(a.x>=b.x)
return true;
else
return false;
}
bool cmp1(el a,el b)
{
if(a.poz<b.poz)
return true;
else
return false;
}
int nr[33];
int main()
{
ifstream f("shop.in");
ofstream g("shop.out");
int n,c,i,pa;
unsigned long long l;
f>>n>>c>>l;
for(i=1;i<=n;i++)
{
f>>v[i].x;
f>>v[i].y;
v[i].poz=i;
}
sort(v+1,v+n+1,cmp);
unsigned long long e=1;
for(i=1;i<=v[1].x;i++)
{
e*=c;
}
pa=v[1].x;
i=1;
int cat,total=0,j;
while(l>0)
{
cat=l/e;
if(cat>v[i].y)
{
l-=v[i].y*e;
v[i].b=v[i].y;
total+=v[i].y;
}
else
{
v[i].b=cat;
total+=cat;
l-=e*cat;
}
for(j=v[i].x;j>v[i+1].x;j--)
e/=c;
i+=1;
}
g<<total<<'\n';
sort(v+1,v+n+1,cmp1);
for(i=1;i<=n;i++)
{
g<<v[i].b<<" ";
}
f.close();
g.close();
return 0;
}