Pagini recente » Cod sursa (job #1488716) | Cod sursa (job #2850320) | Cod sursa (job #171501) | Cod sursa (job #3174339) | Cod sursa (job #844607)
Cod sursa(job #844607)
#include <stdio.h>
#include <algorithm>
using namespace std;
struct tractor //Fane Tractoristul
{
int C, T;
} x[100100];
inline bool comp(tractor A, tractor B)
{
return (double)A.C / A.T > (double)B.C / B.T;
}
int solve(int T, int N, int M)
{
int i;
for (i = 1; i <= N; i ++)
{
if (M - x[i].C * (T / x[i].T) <= 0)
return i;
M = M - x[i].C * (T / x[i].T);
}
return -1;
}
int main()
{
int i, N, M, cmax = 0, tx;
double rep = 0;
freopen("garaj.in", "r", stdin);
freopen("garaj.out", "w", stdout);
scanf("%d%d", &N, &M);
for (i = 1; i <= N; i ++)
{
scanf("%d%d", &x[i].C, &x[i].T);
x[i].T = x[i].T * 2;
if ((double)x[i].C / x[i].T - rep > 0.00000001)
rep = x[i].C / x[i].T, cmax = x[i].C, tx = x[i].T;
}
int uppBound = M / cmax;
if (M % cmax)
uppBound ++;
uppBound = uppBound * tx;
sort(x + 1, x + N + 1, comp);
int st = 1, dr = uppBound, med, ret;
while (st <= dr)
{
med = (st + dr) / 2;
if (solve(med, N, M) != -1)
ret = med, dr = med - 1;
else
st = med + 1;
}
printf("%d %d", ret, solve(ret, N, M));
return 0;
}