Cod sursa(job #322831)

Utilizator taloibogdanTaloi Bogdan Cristian taloibogdan Data 9 iunie 2009 22:32:46
Problema Garaj Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<stdio.h>
#include<algorithm>
using namespace std;
struct che{long x,t;}a[100050];
long n,m,i,st,dr,mi,s,t,nr,maxx;
long cmp(che a,che b)
{if(t/a.t*a.x>t/b.t*b.x)return 1;
return 0;}
int main()
{
 freopen("garaj.in","r",stdin);
 freopen("garaj.out","w",stdout);
 scanf("%ld%ld",&n,&m);
 for(i=1;i<=n;++i)
    {scanf("%ld%ld",&a[i].x,&a[i].t);
     a[i].t*=2;}
//     if(m/a[i].x*a[i].t>maxx)maxx=m/a[i].x*a[i].t;}
 st=1;dr=1000000000;
 while(st<=dr)
  {mi=st+((dr-st)>>1);
   s=0;
   for(i=1;i<=n;++i)
      s+=(a[i].x*(mi/a[i].t));
   if(s>=m)
     {t=mi;dr=mi-1;}
     else st=mi+1;}
 sort(a+1,a+n+1,cmp);
 for(i=1;i<=n&&m>0;++i,++nr)
    m-=(t/a[i].t*a[i].x);
 printf("%ld %ld\n",t,nr);
 return 0;
}