Pagini recente » Cod sursa (job #2780936) | Cod sursa (job #1182497) | Cod sursa (job #1247085) | Cod sursa (job #2834668) | Cod sursa (job #1646186)
#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,pivot=(b+e)/2;
while(b<=e){
while(cost[b]*timp[pivot]<timp[b]*cost[pivot]) b++;
while(cost[e]*timp[pivot]>timp[e]*cost[pivot]) 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;
}