Cod sursa(job #2496055)
Utilizator | Groza Iulia Diana Groza_Iulia_Diana | Data | 20 noiembrie 2019 10:12:08 |
---|---|---|---|
Problema | Shop | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | ad_hoc | Marime | 0.65 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("shop.in");
ofstream fout("shop.out");
long long n, c, l, p, nr1, nr2, t[105], a[105], b[105];
int main()
{
fin >> n >> c >> l;
for(int i=1; i<=n; i++)
{
fin >> nr1 >> nr2;
a[nr1]=nr2;
t[i]=nr1;
}
while(l)
{
b[nr2++]=l%c;
l/=c;
}
p=b[0];
for(int i=60; i>=1; i--)
{
if(b[i]>a[i])
{
b[i-1]+=(b[i]-a[i])*c;
b[i]=a[i];
}
p+=b[i];
}
fout << p << "\n";
for(int i=1; i<=n; i++)
fout << b[t[i]] << " ";
return 0;
}