Cod sursa(job #1936557)

Utilizator giotoPopescu Ioan gioto Data 23 martie 2017 10:52:43
Problema Garaj Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 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 = 100000, Min;
    sort(a + 1, a + n + 1, cmp);
    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) {
                cam = i;
                break;
            }
        }
        if(NR >= m) Min = cam, dr = mij - 1;
        else st = mij + 1;
    }
    printf("%d %d", st, Min);
    return 0;
}