Pagini recente » Cod sursa (job #1333236) | Cod sursa (job #2261270) | Cod sursa (job #1875954) | Cod sursa (job #1904617) | Cod sursa (job #1814165)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <climits>
using namespace std;
const int nmax=100005;
int cost,x,i,j,n,m,k,p,camioane;
int t[nmax],c[nmax];
bool ok;
bool check(int x)
{
cost=0;
for(i=1;i<=n;i++)
{
cost+=(x/t[i])*c[i];
}
//if(cost<0) cost=m;
return (cost>=m);
}
int main()
{
ifstream f("garaj.in");
ofstream g("garaj.out");
f>>n>>m;
for(i=1;i<=n;i++)
{
f>>c[i]>>t[i];
t[i]*=2;
}
k=INT_MAX;
for(p=30;p>=0;p--)
{
if(check(k-(1<<p)))k-=(1<<p);
}
for(i=1;i<=n;i++)
t[i]=(k/t[i])*c[i];
sort(t+1,t+n+1);cost=0;
for(i=n;i>=1&&cost<m;i--)
{
camioane++;
cost+=t[i];
//if(cost<0) cost=m;
}
g<<k<<' '<<camioane;
return 0;
}