Cod sursa(job #851898)

Utilizator stoicatheoFlirk Navok stoicatheo Data 10 ianuarie 2013 16:37:01
Problema Garaj Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <fstream>
#include <algorithm>
using namespace std;
 
int n, m, tmin, v[100100];
struct {int c, t;} a[100100];
 
inline bool check(int nr)
{
    int sum = 0;
    for (int i = 1; i <= n; ++i)
    {
        sum = sum + nr / (a[i].t << 1) * a[i].c;
        if (sum >= m) return true;
    }
    return false;
}
 
inline int bs()
{
    int i, cnt = (1 << 25);
    for (i = 1 << 25; cnt > 0; cnt >>= 1)
        if (i - cnt > 0)
            if (check(i - cnt))
                i -= cnt;
    return i;
}
int main()
{
    ifstream f("garaj.in");
    ofstream g("garaj.out");
 
    f >> n >> m;
    for (int i = 1; i <= n; ++i)
        f >> a[i].c >> a[i].t;
 
    tmin = bs();
 
    for (int i = 1; i <= n; ++i)
        v[i] = tmin / (a[i].t << 1) * a[i].c;
 
    sort(v + 1, v + n + 1, greater<int>());
 
    for (int i = 1, sum = 0; i <= n; ++i)
    {
        sum += v[i];
        if (sum >= m)
        {
            g << tmin << ' ' << i << '\n';
            g.close();
            return 0;
        }
    }
 
    g.close();
    return 0;
}