Cod sursa(job #461533)

Utilizator SpiderManSimoiu Robert SpiderMan Data 7 iunie 2010 12:47:27
Problema Garaj Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
const char FIN[] = "garaj.in", FOU[] = "garaj.out";
const int MAX_N = 100005;

struct vec
{
    int C, T;
} ;

int N, M;
unsigned int V[MAX_N];
vec X[MAX_N];

ll check (int timp)
{
    ll sol = 0;

    for (int i = 1; i <= N; ++i)
        sol += ( V[i] = ( X[i].C * ( timp / X[i].T ) ) );

    return sol;
}

void bin_ser ()
{
    int i, step;
    for (i = 0, step = 1 << 30 ; step ; step >>= 1)
        if ( check ( i + step ) < M )
            i += step;

    printf ("%d ", ++i << 1);

    check ( i );
}

void solve ()
{
    int i;
    for (i = 1; i <= N; ++i)
        if ( ( M -= V[i] ) <= 0 ) break;

    printf("%d\n", i );
}

int main()
{
    freopen(FIN, "r", stdin);
    freopen(FOU, "w", stdout);

    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; ++i)
        scanf("%d %d", &X[i].C, &X[i].T);

    bin_ser () ;

    sort ( V + 1, V + N + 1, greater<int> () );

    solve () ;

    return 0;
}