Cod sursa(job #2431996)

Utilizator mirceatlxhaha haha mirceatlx Data 21 iunie 2019 15:38:50
Problema Shop Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream fin("shop.in");
ofstream fout("shop.out");

int N,C,L,nrm = 0;
struct mond
{
    long long val,nr;
    int used = 0;
    int first;
};
mond v[35];
long long cc[35];
void Read()
{
    int x;
    fin>>N>>C>>L;
    for(int i = 1;i<=N;i++)
    {
        fin>>v[i].val>>v[i].nr;
        v[i].first = i;
    }
    cc[0]=1;
    for(int i=1;i<=N;i++)
        cc[i]=cc[i-1]*C;

}

bool CMP(mond a,mond b)
{
    return a.val > b.val;
}

bool CMP1(mond a,mond b)
{
    return a.first < b.first;
}

void Sorting()
{
    sort(v+1,v+N+1,CMP);
}

void Sorting1()
{
    sort(v+1,v+N+1,CMP1);
}
void Print()
{
    fout<<nrm<<"\n";
    for(int i =1 ;i<=N;i++)
        fout<<v[i].used<<" ";
}

void Solve()
{
    int k=1;
    while(L!=0)
    {
        while(v[k].nr!=0 && L>0)
        {
            L = L -cc[v[k].val];
            v[k].used++;
            nrm++;
            v[k].nr--;
        }
        if(L<0)
        {
            nrm--;
            v[k].used--;
            L = L + cc[v[k].val];
        }
        k++;

    }
}

int main()
{
    Read();
    Sorting();
    Solve();
    Sorting1();
    Print();
    return 0;
}