Cod sursa(job #2738320)

Utilizator stefantagaTaga Stefan stefantaga Data 5 aprilie 2021 18:10:24
Problema Minim2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("minim2.in");
ofstream g("minim2.out");
int n,x;
long double sum,a2,b2,record;
auto compare = [] (pair <long double,int> a,pair <long double ,int> b)
{
    long double dif1,dif2;
    if (a.first==1)
    {
        dif1=a.first-a.first*a2;
    }
    else
    {
        dif1=a.first-a.first*b2;
    }
    if (b.first==1)
    {
        dif2=b.first-b.first*a2;
    }
    else
    {
        dif2=b.first-b.first*b2;
    }
    return dif1<dif2;
};
priority_queue <pair <long double,int>,vector <pair <long double,int> > , decltype(compare)> h(compare);
int i,nr;
long double dif;
pair <long double,int> acum;
int main()
{
    f>>n;
    for (i=1;i<=n;i++)
    {
        f>>x;
        sum+=x;
        h.push({x,1});
    }
    f>>a2>>b2>>record;
    while (sum>record)
    {
        acum=h.top();
        h.pop();
        if (acum.second==1)
        {
            dif=acum.first-acum.first*a2;
            sum=sum-dif;
            acum.first=acum.first*a2;
            h.push({acum.first,0});
        }
        else
        {
            dif=acum.first-acum.first*b2;
            sum=sum-dif;
            acum.first=acum.first*b2;
            h.push({acum.first,0});
        }
        nr++;
    }
    g<<nr-1;
    return 0;
}