Pagini recente » Cod sursa (job #2488080) | Cod sursa (job #1943313) | Cod sursa (job #720477) | Cod sursa (job #2299599) | Cod sursa (job #337415)
Cod sursa(job #337415)
#include<stdio.h>
#include<algorithm>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pii pair<int,int>
#define N 100010
int n,m;
int t,cate;
pii v[N];
int ind[N];
inline void citire()
{
scanf("%d%d",&n,&m);
for(int i=0; i<n; ++i)
{
scanf("%d%d",&v[i].fs,&v[i].sc);
ind[i]=i;
}
}
bool compar(const int &x,const int &y)
{
if(t/(2*v[x].sc)*v[x].fs>t/(2*v[y].sc)*v[y].fs)
return true;
return false;
}
inline bool vezi()
{
cate=0;
sort(ind,ind+n,compar);
int i=0;
int aux=0;
for(; i<n; ++i)
{
aux+=t/(2*v[ind[i]].sc)*v[ind[i]].fs;
if(aux>=m)
{
cate=i+1;
return true;
}
}
cate=n+1;
return false;
}
int main()
{
freopen("garaj.in","r",stdin);
freopen("garaj.out","w",stdout);
citire();
int p=1,u=200000000;
while(p<u)
{
t=(p+u)>>1;
if(vezi())
u=t;
else
p=t+1;
}
t=p;
if(vezi()==false)
{
++t;
vezi();
}
printf("%d %d\n",t,cate);
return 0;
}