Mai intai trebuie sa te autentifici.
Cod sursa(job #1757029)
Utilizator | Data | 14 septembrie 2016 11:06:09 | |
---|---|---|---|
Problema | Shop | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <fstream>
#define nmax 35
using namespace std;
ifstream f("shop.in");
ofstream g("shop.out");
long long a[nmax],b[nmax],l,p;
int n,c,t[nmax];
int main()
{
int i,j,k;
f>>n>>c>>l;
for (i=1;i<=n;i++) {
f>>j>>k;
a[j]=k;
t[i]=j;
}
k=0;
while (l) {
b[k++]=l%c;
l/=c;
}
for (i=32;i>=1;i--) {
if (b[i]>a[i]) {
b[i-1]+=1LL*(b[i]-a[i])*c;
b[i]=a[i];
}
p+=b[i];
}
p+=b[0];
g<<p<<'\n';
for (i=1;i<=n;i++)
g<<b[t[i]]<<' ';
return 0;
}