Pagini recente » Cod sursa (job #2640839) | Cod sursa (job #140004) | Cod sursa (job #688642) | Cod sursa (job #1636810) | Cod sursa (job #718953)
Cod sursa(job #718953)
#include <fstream>
#define NMAx 64
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
struct Moneda{int Nr,Ind;}V[NMAx];
int N,C,BaseC[NMAx],Cont[NMAx];
long long L,Sol;
void citire() {
int i,A,B;
ifstream in("shop.in");
in>>N>>C>>L;
for(i=1;i<=N;i++) {
in>>A>>B;
V[A].Nr=B;
V[A].Ind=i;
}
in.close();
}
void afis() {
ofstream out("shop.out");
out<<Sol<<'\n';
for(int i=1;i<=N;i++)
out<<Cont[i]<<' ';
out<<'\n';
out.close();
}
int main() {
int K,S;
long long Total=0;
citire();
for(K=0;L;K++,L/=C)
BaseC[K]=L%C;
for(;K>=0;K--) {
Total=Total*C+BaseC[K];
S=min(V[K].Nr,Total);
Total-=S;
Cont[ V[K].Ind ]=S;
Sol+=S;
}
afis();
return 0;
}