Cod sursa(job #1120314)

Utilizator dutzulBodnariuc Dan Alexandru dutzul Data 24 februarie 2014 23:03:29
Problema Garaj Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <iostream>
using namespace std;

ifstream f("garaj.in");
ofstream g("garaj.out"); 

#define ll long long
#include <algorithm>
#define cout g
#define LE 100666

ll C[LE],T[LE],V[LE],nrs;
int i,nr,n;

bool ck(ll timp)
{
	int i;
	ll suma=0;
	for(i=1;i<=n;++i) suma+=C[i]*(timp/((ll)2*T[i]));
	return (suma<nrs?false:true);
}

ll bs()
{
	ll pos,step;
	step=((ll)1<<(ll)50);
	
	for(pos=0;step;step>>=(ll)1)
		if (ck(pos+step)==false)
			pos+=step;
		
	return pos+1;
}

int main()
{
	f>>n>>nrs;
	for(i=1;i<=n;++i) f>>C[i]>>T[i];
	ll Nr=bs();
	for(i=1;i<=n;++i) V[i]=C[i]*(Nr/(2*T[i]));
	sort(V+1,V+n+1);
	ll suma=0,res=0;
	
	for(i=n;i>0;--i) 
	{
		suma+=V[i];
		if (suma>nrs) {res=n-i+1;break;}
	}
	
	cout<<Nr<<" "<<res<<'\n';
	
	return 0;
}