Cod sursa(job #1374814)

Utilizator andrei_diaconuAndrei Diaconu andrei_diaconu Data 5 martie 2015 10:52:26
Problema Garaj Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <algorithm>

#define NMax 100010

using namespace std;

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

int n, m, cmin, nrc;
long long st, dr, mid, tmin, tcam[NMax];
struct camion
{
	int c;
	int t;
}c[NMax];

bool cmp(const int a, const int b)
{
	return a > b;
}

long long test_time(long long time)
{
	long long nsticle = 0;
	for (int i = 1; i <= n; i++)
		nsticle += time / c[i].t  * c[i].c;
	return nsticle;
}

int main()
{
	f >> n >> m;
	for (int i = 1; i <= n; i++)  {
		int tmp;
		f >> c[i].c >> tmp;
		c[i].t = 2 * tmp;
	}
	st = 1;
	dr = 1LL << 60;
	while (st <= dr) {
		mid = (st + dr) / 2;
		long long nsticle = test_time(mid);
		if (nsticle >= 1LL * m) {
			tmin = mid;
			dr = mid - 1;
		}
		else
			st = mid + 1;
	}
	g << tmin << " ";
	for (int i = 1; i <= n; i++)
		tcam[i] = tmin * c[i].c / c[i].t;
	sort(tcam + 1, tcam + n + 1, cmp);
	for (int i = 1; i <= n && m > 0; i++, nrc++)
		m -= tcam[i];
	g << nrc;
}