Cod sursa(job #718953)

Utilizator okros_alexandruOkros Alexandru okros_alexandru Data 21 martie 2012 11:41:34
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#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;
	
}