Pagini recente » Profil Daria09 | Statistici Radu Dobrin (rafu) | Profil usureluflorian | Cod sursa (job #1170039) | Cod sursa (job #2496056)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ifstream fin("shop.in");
ofstream fout("shop.out");
ll n, c, l, k, nr1, nr2, a[105], b[105], t[105];
int main()
{
fin >> n >> c >> l;
for(int i=1; i<=n; i++)
{
fin >> nr1 >> nr2;
a[nr1]=nr2;
b[i]=nr1;
}
while(l)
{
t[k++]=l%c;
l/=c;
}
int p=b[0];
for(int i=60; i>=1; i--)
{
if(t[i]>a[i])
{
t[i-1]+=(t[i]-a[i])*c;
t[i]=a[i];
}
p+=t[i];
}
fout << p << "\n";
for(int i=1; i<=n; i++)
fout << t[b[i]] << " ";
return 0;
}