Pagini recente » Cod sursa (job #3169330) | Cod sursa (job #2888804) | Cod sursa (job #547396) | Cod sursa (job #1079277) | Cod sursa (job #1647936)
#include <cstdio>
#include<algorithm>
#define MAX 100000
#define LIM 100000000
using namespace std;
struct aa{
int c, t;
double f;
}; aa v[MAX+1];
int vc[MAX+1];
bool cresc(const int a, const int b){
return a>b;
}
int n;
inline int ok(int timp, int m)
{
int i=1, x=0;
while(x<m&&i<=n){
x+=timp/(v[i].t*2)*v[i].c;
i++;
}
if(x>=m)
return 1;
return 0;
}
int main()
{
freopen("garaj.in", "r", stdin);
freopen("garaj.out","w", stdout);
int i, maxi=-1, s=0;
int m, st, dr, mij, mintime, x=0;
scanf("%d%d", &n, &m);
for(i=1;i<=n;i++){
scanf("%d%d", &v[i].c, &v[i].t);
}
dr=LIM;
mintime=dr+1;
st=1;
while(st<=dr)
{
mij=(st+dr)/2;
if(ok(mij, m))
{
if(mij<mintime)
mintime=mij;
dr=mij-1;
}
else st=mij+1;
}
printf("%d ", mintime);
for(i=1;i<=n;i++)
vc[i]=mintime/(2*v[i].t)*v[i].c;
sort(vc+1, vc+n+1, cresc);
i=1;
while(x<m)
{
x+=vc[i];
i++;
s++;
}
printf("%d", s);
return 0;
}