Pagini recente » Cod sursa (job #2204298) | Cod sursa (job #1029777) | Cod sursa (job #656921) | Cod sursa (job #363416) | Cod sursa (job #1646212)
#include <cstdio>
#define MAXN 100000
int cost[MAXN],timp[MAXN],con,m;
inline long long cauta(int t,int n){
long long s=0;
int i;
con=0;
for(i=n-1;i>=0;i--){
if(s<m)
con++;
s=s+1LL*cost[i]*(t/(timp[i]*2));
}
return s;
}
inline void swap(int b,int e,int *v){
int aux=v[b];
v[b]=v[e];
v[e]=aux;
}
void myqsort(int begin,int end){
int b=begin,e=end,tpivot=timp[(b+e)/2],cpivot=cost[(b+e)/2];
while(b<=e){
while(cost[b]*tpivot<timp[b]*cpivot) b++;
while(cost[e]*tpivot>timp[e]*cpivot) e--;
if(b<=e){
swap(b,e,cost);
swap(b,e,timp);
b++;e--;
}
}
if(begin<e) myqsort(begin,e);
if(b<end) myqsort(b,end);
}
int main(){
FILE*fi,*fout;
int n,rez,pas,i;
fi=fopen("garaj.in" ,"r");
fout=fopen("garaj.out" ,"w");
fscanf(fi,"%d%d" ,&n,&m);
for(i=0;i<n;i++)
fscanf(fi,"%d%d" ,&cost[i],&timp[i]);
myqsort(0,n-1);
rez=0;
for(pas=1<<30;pas;pas>>=1)
if(cauta(rez+pas,n)<m)
rez+=pas;
cauta(rez+1,n);
fprintf(fout,"%d %d" ,rez+1,con);
fclose(fi);
fclose(fout);
return 0;
}