Pagini recente » Cod sursa (job #2865000) | Cod sursa (job #3195198) | Cod sursa (job #3235390) | Cod sursa (job #622973) | Cod sursa (job #1399361)
#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,part,cand,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;
part=v[i].c;
cand=0;
while(part<M)
{
part+=v[i].c;
cand+=v[i].t;
}
if(cand+v[i].t>smax)
smax=cand+v[i].t;
}
int st=1,dr=smax,mid;
while(st<dr)
{
mid=(st+dr)/2;
sum=0;
for(i=1; i<=N; i++)
{
part=0;
cand=0;
while(part<=mid)
{
part+=v[i].t;
cand+=v[i].c;
}
cand-=v[i].c;
sum+=cand;
if(sum>=M)
{
dr=mid;
i=N+1;
sol=mid;
if(sol<T)
T=sol;
}
}
if(sum<M)
{
st=mid+1;
}
}
for(i=1; i<=N; i++)
{
part=0;
cand=0;
while(part<T)
{
part+=v[i].c;
cand+=v[i].t;
}
v[i].s=cand;
}
sort(v+1,v+N+1,mycomp);
part=0;
i=1;
while(part<T&&i<=N)
{
part+=v[i].s;
i++;
}
sol=i-1;
out<<T<<" "<<sol;
return 0;
}