Cod sursa(job #1372306)

Utilizator ovidiuz98Zamfir Ovidiu ovidiuz98 Data 4 martie 2015 12:44:10
Problema Garaj Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>
#include <algorithm>
#define DIM 100005

using namespace std;

ifstream fin("garaj.in");
ofstream fout("garaj.out");

int N,p,u,mid,S,sol,nr;
pair <int,int> V[DIM];
int ok(int x){
    int sol=0;
    nr=0;
    for(int i=1;i<=N;i++){
        int c=x/(2*V[i].second);
        nr+=(c!=0);
        int s=c*V[i].first;
        sol+=s;
        if(sol>=S)
            return 1;
    }
    return 0;
}
int main(){
    fin>>N>>S;
    for(int i=1;i<=N;i++){
        fin>>V[i].first>>V[i].second;
    }
    sort(V+1,V+N+1);
    p=1;
    u=DIM*1000;
    while(p<=u){
        mid=(p+u)>>1;
        if(ok(mid)){
            sol=mid;
            u=mid-1;
        }
        else
            p=mid+1;
    }
    ok(sol);
    fout<<sol<<" "<<nr<<"\n";
    fin.close();fout.close();
    return 0;
}