Cod sursa(job #973176)

Utilizator marius135Dumitran Adrian Marius marius135 Data 13 iulie 2013 17:19:30
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

int nr[64], cate[64], solution[64];

int main() {
	
	freopen("shop.in", "r", stdin);
	freopen("shop.out", "w", stdout);
	
	int N, C;
	long long L;
	cin>>N>>C>>L;
	
	for( int i = 0; i < N; ++i) {
		int x, y;
		cin>>x>>y;
		nr[x] = y;
		cate[x] = i;
	}
	long long x = 1;
	int count2 = 0;
	
	while( x * C < L )  {
		count2++;
		x*= C;
	}
	
	int total = 0;
	while( x ) {
		if( nr[count2] && L >= x) {
			int monezi = L / x;
			monezi = min( nr[count2], monezi);
			total += monezi;
			solution[ cate[count2]] = monezi;
			L -= monezi * x;
		}
		x /= C;
		count2--;
	}
	
	cout<<total<<endl;
	for( int i = 0; i < N; ++i)
		cout<<solution[i]<<" ";
	cout<<endl;
	
	
}