Pagini recente » Cod sursa (job #928461) | Cod sursa (job #346616) | Cod sursa (job #3258858) | Cod sursa (job #1354870) | Cod sursa (job #874817)
Cod sursa(job #874817)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream fin("lapte.in");
ofstream fout("lapte.out");
int N; int T;
struct timp { int t1; int t2; double f; int ind;int c ; };
const int bound = 1<<13;
timp t[102];
bool cmp(timp a, timp b){
return a.f < b.f;
}
void Read() {
fin >> N>> T;
for(int i = 1; i <= N; ++i){
fin >> t[i].t1 >> t[i].t2;
t[i].f = (double)t[i].t1/t[i].t2;
t[i].ind = i;
}
sort(&t[1], &t[1 + N], cmp);
}
bool bea(int x){
int cnt = 1, B1 = 0, B2 = 0;
for(int i = 1;i <= N; ++i)
t[i].c = 0;
while(cnt <= N && B1 + x / t[cnt].t1 <= T){
B1 += (x/t[cnt].t1);
t[cnt].c = x/t[cnt].t1;
cnt++;
}
if(B1 < T && cnt <= N){
B2 += (x - (T - B1) * t[cnt].t1) / t[cnt].t2;
t[cnt].c = (T - B1);
cnt++;
}
for(int i = cnt; i <= N; ++i)
B2 += (x/t[i].t2);
return B2 >= T;
}
int bs(){
int step, pos;
for(step = 1; step <= bound; (step <<=1));
for(pos = 0; step; (step >>= 1))
if(pos + step <= bound && bea(pos + step) == false)
pos += step;
return pos;
}
bool cmp2 (timp a, timp b){
return a.ind < b.ind;
}
int main (){
Read ();
int x = bs() + 1;
fout << x <<'\n';
bea(x);
sort(&t[1], &t[1 + N], cmp2);
for(int i = 1; i <= N; ++i)
fout << t[i].c <<" "<<(x - t[i].c * t[i].t1)/t[i].t2<<'\n';
return 0;
}