Pagini recente » Cod sursa (job #2934038) | Cod sursa (job #2606553) | Cod sursa (job #1935684) | Cod sursa (job #3207817) | Cod sursa (job #741397)
Cod sursa(job #741397)
#include <fstream>
#include <iostream>
#include <algorithm>
#define ll long long
#define nmax 35
#define x first
#define y second
using namespace std;
ll n, c, l, frec[nmax], Min;
pair<ll, pair<ll, ll> > v[nmax];
ifstream f("shop.in");
ofstream g("shop.out");
ll putere(ll a, ll b){
ll rez = 1;
while(b){
if( b % 2 == 1) rez = rez * a;
a = a * a;
b = b / 2;
}
return rez;
}
void citeste(){
f >> n >> c >> l;
for(int i=1; i<=n; i++){
int a,b;
f >> a >> b;
v[i].x = putere(c,a);
v[i].y.x= b;
v[i].y.y = i;
}
sort(v+1, v+n+1);
}
void rezolva(){
for(int i=n; i; i--){
if (v[i].x > l) continue;
while(v[i].x <= l && l && v[i].y.x){
frec[v[i].y.y]++;
v[i].y.x--;
l-=v[i].x;
}
Min += frec[v[i].y.y];
}
}
void scrie(){
g << Min << "\n";
for(int i=1; i<=n; i++) g << frec[i] << " ";
}
int main(){
citeste();
rezolva();
scrie();
f.close();
g.close();
return 0;
}