Pagini recente » Cod sursa (job #1811322) | Cod sursa (job #565650) | Cod sursa (job #761068) | Cod sursa (job #729109) | Cod sursa (job #874710)
Cod sursa(job #874710)
#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; };
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 <= T; (step <<=1));
for(pos = 0; step; (step >>= 1))
if(pos + step <= T && 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();
fout << x + 1<<'\n';
bea(x + 1);
++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;
}