Cod sursa(job #2910639)

Utilizator AlexSerban21Serban Alexandru AlexSerban21 Data 23 iunie 2022 10:57:02
Problema Garaj Scor 10
Compilator cpp-64 Status done
Runda 3_iulie Marime 0.72 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("garaj.in");
ofstream fout ("garaj.out");
int n,m,cc,tt,timp,i,j,s;
struct element
{
    int c,t;
};
element v[300003];
int cmp (element a,element b)
{
    if (a.t==b.t)
        return a.c>b.c;
    return a.t<b.t;
}
int main()
{
    fin>>n>>m;
    for (i=1; i<=n; i++)
        fin>>v[i].c>>v[i].t;
    sort (v+1,v+n+1,cmp);
    cc=v[1].c;
    tt=v[1].t;
    for (timp=1; ; timp++)
    {
        s=0;
        for (j=1; j<=n; j++)
        {
            s=s+v[j].c*(timp/v[j].t);
            if (s>=m)
            {
                fout<<timp*2<<" "<<j;
                return 0;
            }
        }
    }
    return 0;
}