Cod sursa(job #1490502)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 23 septembrie 2015 17:55:12
Problema Garaj Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <cstdio>
#include <algorithm>
#define MAXN 100000
typedef struct{
    int c, t;
}mycreation;
mycreation v[MAXN];
int n, rez;
bool cmp(const mycreation a, const mycreation b){
    return (a.c*(rez/a.t)>b.c*(rez/b.t));
}
inline long long cat(int x){
    long long s=0;
    for(int i=0; i<n; i++){
        s+=v[i].c*(x/v[i].t);
    }
    return s;
}
int main(){
    int m, i, pas, s;
    FILE *fin, *fout;
    fin=fopen("garaj.in", "r");
    fout=fopen("garaj.out", "w");
    fscanf(fin, "%d%d", &n, &m);
    for(i=0; i<n; i++){
        fscanf(fin, "%d%d", &v[i].c, &v[i].t);
        v[i].t*=2;
    }
    rez=-1;
    for(pas=1<<10; pas; pas>>=1){
        if(cat(rez+pas)<m){
            rez+=pas;
        }
    }
    rez++;
    std::sort(v, v+n, cmp);
    i=0;
    s=0;
    while((s<m)&&(i<n)){
        s+=v[i].c*(rez/v[i].t);
        i++;
    }
    fprintf(fout, "%d %d", rez, i);
    fclose(fin);
    fclose(fout);
    return 0;
}