Pagini recente » Profil mihnea.anghel | Cod sursa (job #1287512) | Cod sursa (job #774109) | Cod sursa (job #442201) | Cod sursa (job #977135)
Cod sursa(job #977135)
#include<stdio.h>
#include<algorithm>
using namespace std;
#define NMAX 100000
int n,sticle,tmin,c[NMAX+5],t[NMAX+5],cate[NMAX+5];
bool check (int ti) {
int i,cnt=0;
for(i=1;i<=n;i++) {
cnt+=ti/(t[i]*2)*c[i];
if(cnt>=sticle)
return 1;
}
return 0;
}
void bs (int left, int right) {
int mid;
while(left<=right) {
mid=left+(right-left)/2;
if(check(mid)) {
tmin=mid;
right=mid-1;
}
else
left=mid+1;
}
}
int main() {
freopen("garaj.in","r",stdin);
freopen("garaj.out","w",stdout);
int i;
scanf("%d%d",&n,&sticle);
for(i=1;i<=n;i++)
scanf("%d%d",&c[i],&t[i]);
bs(1,2*sticle);
for(i=1;i<=n;i++)
cate[i]=tmin/(t[i]*2)*c[i];
sort(cate+1,cate+1+n);
printf("%d ",tmin);
for(i=n;i>=1;i--) {
sticle-=cate[i];
if(sticle<=0) {
printf("%d\n",n-i+1);
return 0;
}
}
return 0;
}