Pagini recente » Cod sursa (job #2623887) | Cod sursa (job #2047511) | Cod sursa (job #2944506) | Cod sursa (job #583830) | Cod sursa (job #1399388)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int maxn = 100010;
struct camion
{
int c,t,s;
} v[maxn];
int N,M,smax,sum,T=1<<20,sol;
inline bool mycomp(camion a,camion b)
{
return a.s<b.s;
}
int main()
{
ifstream in("garaj.in");
ofstream out("garaj.out");
in>>N>>M;
int i;
for(i=1; i<=N; i++)
{
in>>v[i].c>>v[i].t;
v[i].t*=2;
}
smax=200000000;
int st=1,dr=smax,mid;
while(st<dr)
{
mid=(st+dr)/2;
sum=0;
for(i=1; i<=N; i++)
{
sum+=(mid/v[i].t)*v[i].c;
if(sum>=M)
{
dr=mid;
i=N+1;
if(mid<T)
T=mid;
}
}
if(sum<M)
{
st=mid+1;
}
}
for(i=1; i<=N; i++)
v[i].s=(T/v[i].t)*v[i].c;
sort(v+1,v+N+1,mycomp);
sol=0;
i=1;
while(sol<T&&i<=N)
{
sol+=v[i].s;
i++;
}
sol=i-1;
out<<T<<" "<<sol;
return 0;
}