Cod sursa(job #1936604)

Utilizator giotoPopescu Ioan gioto Data 23 martie 2017 11:14:30
Problema Garaj Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <cstdio>
#include <algorithm>
using namespace std;

int n, m;
struct camion{
    int c, t;
}a[100002];
inline bool cmp(camion x, camion y){
    return x.t < y.t;
}
int main()
{
    freopen("garaj.in", "r", stdin);
    freopen("garaj.out", "w", stdout);
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n ; ++i)
        scanf("%d%d", &a[i].c, &a[i].t), a[i].t *= 2;
    int st = 1, dr = 2000000000;
    while(st <= dr){
        int mij = (st + dr) / 2;
        int NR = 0, cam = 0;
        for(int i = 1; i <= n ; ++i){
            NR = NR + (mij / a[i].t) * a[i].c;
            if(NR >= m) break;

        }
        if(NR >= m)dr = mij - 1;
        else st = mij + 1;
    }
    int NR = 0;
    for(int i = 1; i <= n ; ++i){
        a[i].t = (st / a[i].t) * a[i].c;
        NR = NR + a[i].t;
    }
    sort(a + 1, a + n + 1, cmp);
    int Min = n, i = 1;
    while(NR >= m){
        NR = NR - a[i].t;
        ++i;
        if(NR < m) break;
        --Min;
    }
    printf("%d %d", st, Min);
    return 0;
}