Cod sursa(job #778565)

Utilizator maritimCristian Lambru maritim Data 15 august 2012 00:08:30
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include<stdio.h>
#include<algorithm>
using namespace std;

FILE *f = fopen("shop.in","r");
FILE *g = fopen("shop.out","w");

typedef struct
{
	int x,y,poz;
} xy;

typedef struct Compare
{
	bool operator() (const xy a,const xy b) { return a.x > b.x; }
} ICompare;

#define ll long long
#define MaxN 50

int N,B;
ll L,Sol,SolV[MaxN];
xy A[MaxN];

void citire(void)
{
	fscanf(f,"%d %d %lld\n",&N,&B,&L);
	for(int i=1;i<=N;A[i].poz = i, ++i)
		fscanf(f,"%d %d",&A[i].x,&A[i].y);
}

inline ll Putere(ll a,int put)
{
	ll Sol = 1;
	
	for(;put;--put,Sol *= a);
	
	return Sol;
}

inline int min(int a,int b)
{
	return a < b ? a : b;
}

void Rezolvare(void)
{
	sort(A+1,A+N+1,ICompare());
	
	for(int i=1;i<=N && L != 0;i++)
	{
		SolV[A[i].poz] = min(A[i].y,L/Putere(B,A[i].x));
		Sol += SolV[A[i].poz];
		L -= 1LL*SolV[A[i].poz]*Putere(B,A[i].x);
	}
}

int main()
{
	citire();
	Rezolvare();
	
	fprintf(g,"%lld\n",Sol);
	for(int i=1;i<=N;i++)
		fprintf(g,"%lld ",SolV[i]);
}