Pagini recente » Profil aalleexxaa | Cod sursa (job #2149574) | Cod sursa (job #1570087) | Cod sursa (job #1532834) | Cod sursa (job #977129)
Cod sursa(job #977129)
#include<stdio.h>
#include<algorithm>
using namespace std;
int tmin,sticle,n;
struct CAMION {
int c,t;
};
CAMION c[100010];
bool ok (int timp) {
int count=0,i;
for(i=1;i<=n;i++)
count=count+timp/c[i].t*c[i].c;
if(count>=sticle)
return 1;
return 0;
}
class cmp {
public:
bool inline operator () (const CAMION &a, const CAMION &b){
return tmin/a.t*a.c > tmin/b.t*b.c;
}
};
int bs (int left, int right) {
int mid,res;
while(left<=right) {
mid=left+(right-left)/2;
if(ok(mid)) {
right=mid-1;
res=mid;
}
else
left=mid+1;
}
return res;
}
int solve (int t) {
int i,count=0;
for(i=1;i<=n;i++) {
count=count+t/c[i].t*c[i].c;
if(count>=sticle)
return i;
}
}
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].c,&c[i].t);
c[i].t<<=1;
}
tmin=bs(1,500000);
sort(c+1,c+1+n,cmp());
printf("%d %d\n",tmin,solve(tmin));
return 0;
}