Cod sursa(job #2272234)

Utilizator sandupetrascoPetrasco Sandu sandupetrasco Data 29 octombrie 2018 21:13:44
Problema Shop Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair< ll , ll > PII;

struct my{
	ll x, y, idx, cnt;
};


ll n, c, l, rs;
my a[50];

ll po(ll base, ll poww){
	ll rs = 1;
	while (poww){
		if (poww & 1) rs *= base;
		base *= base;

		poww /= 2;
	}

	return rs;
}

vector < ll > V;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	
	ifstream cin("shop.in");
	ofstream cout("shop.out");

	cin >> n >> c >> l;
	for (int i = 1; i <= n; i++){
		cin >> a[i].x >> a[i].y;
		a[i].idx = i;
	}

	sort(a + 1, a + n + 1, [&](my a, my b){ return a.x < b.x; });

	for (int i = 1; i <= n; i++){
		a[i].x = po(c, a[i].x);
	}

	for (int i = n; i && l; i--){
		a[i].cnt = min(l / a[i].x, a[i].y);

		rs += a[i].cnt;
		l -= a[i].cnt * a[i].x;
	}

	sort(a + 1, a + n + 1, [&](my a, my b){ return a.idx < b.idx; });

	cout << rs << "\n";
	for (int i = 1; i <= n; i++) cout << a[i].cnt << " ";

	return 0;
}