Cod sursa(job #137281)

Utilizator tvladTataranu Vlad tvlad Data 17 februarie 2008 10:51:43
Problema Garaj Scor 10
Compilator cpp Status done
Runda preONI 2008, Runda 4, Clasa a 10-a Marime 1 kb
#include <cstdio>
#include <algorithm>
using namespace std;

struct camion { int c, t, ct; };

const int N = 100000;

int n,m;
camion v[N];

bool vrum ( long long t ) {
	long long s = 0;
	for (int i = 0; i < n; ++i) s += v[i].c * (t/v[i].t);
	return (s >= m);
}

bool ct_cmp ( const camion &a, const camion &b ) { return (a.ct > b.ct); }

int vrumvrum ( long long t ) {
	for (int i = 0; i < n; ++i) v[i].ct = v[i].c * (t/v[i].t);
	sort(v,v+n,ct_cmp);
	long long s = 0;
	int i;
	for (i = 0; i < n && s < m; ++i) s += v[i].ct;
	return i;
}

void bs ( long long &t, int &c ) {
	long long step = (long long) 1 << 60;
	for (t = 0; step; step >>= 1) {
		if (!vrum(t + step)) t += step;
	}
	++t;
	c = vrumvrum(t);
}

int main() {
	freopen("garaj.in","rt",stdin);
	freopen("garaj.out","wt",stdout);
	scanf("%d %d",&n,&m);
	for (int i = 0; i < n; ++i) {
		scanf("%d %d",&v[i].c,&v[i].t);
		v[i].t <<= 1;
	}
	long long t; int nc;
	bs(t,nc);
	printf("%lld %d\n",t,nc);
	return 0;
}