Cod sursa(job #771695)

Utilizator ion824Ion Ureche ion824 Data 26 iulie 2012 20:29:36
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include<fstream>
#include<algorithm>
using namespace std;
int a[32],b[32],I[32],nr[32];

long long pow(long long a,long long x){
     long long p=a;
     if(x==0)return 1;
     for(int i=2;i<=x;++i)p=p*a;
     return p;
     }
struct cmp{
       bool operator()(const int &i,const int &j){
            return a[i]>a[j];
            }
       };

int main(void){
    ifstream fin("shop.in");
    ofstream fout("shop.out");
    int N,C,i,nrmon=0; long long S,t,s=0;
    fin>>N>>C>>S;
    for(i=1;i<=N;++i){ fin>>a[i]>>b[i]; I[i]=i; }
    sort(I+1,I+N+1,cmp());
    i=1;
    while(s<S)
    {
     t=pow(C,a[I[i]]);
     while(s+t<=S && b[I[i]]){ s+=t; nr[I[i]]++; b[I[i]]--; ++nrmon; }
     ++i;
    } 
    fout<<nrmon<<'\n';
    for(i=1;i<=N;++i)fout<<nr[i]<<' ';                             
 return 0;   
}