Pagini recente » Cod sursa (job #2356858) | Cod sursa (job #2710074) | Cod sursa (job #1577587) | Cod sursa (job #1659729) | Cod sursa (job #2112785)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("garaj.in");
ofstream fout("garaj.out");
int n, solt, solc;
unsigned long long m;
struct camion{
int c, t;
}a[100002];
inline bool cmp(const camion x, const camion y)
{
if(x.t==y.t)
return x.c>y.c;
return x.t<y.t;
}
int verif(int val)
{
int i, ture_complete, ct_cam=0;
unsigned long long sump=0;
for(i=1; i<=n; i++)
{
ture_complete=val/(2*a[i].t);
sump+=(unsigned long long)ture_complete*a[i].c;
if(ture_complete>0) ct_cam++;
if(sump>=m) return ct_cam;
}
return 0;
}
void bs()
{
int x, st=0, dr=INT_MAX, mijl;
while(st<=dr)
{
mijl=st+(dr-st)/2;
x=verif(mijl);
if(x>0) solt=mijl, solc=x, dr=mijl-1;
else st=mijl+1;
}
}
int main()
{
int i;
fin>>n>>m;
for(i=1; i<=n; i++) fin>>a[i].c>>a[i].t;
sort(a+1,a+n+1,cmp);
bs();
fout<<solt<<' '<<solc<<'\n';
return 0;
}