Cod sursa(job #1373764)

Utilizator vladrochianVlad Rochian vladrochian Data 4 martie 2015 20:29:41
Problema Garaj Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <algorithm>
using namespace std;

const int kMaxN = 100005;

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

int N, M;
struct {
	int c, t;
} truck[kMaxN];
int amount[kMaxN];
int tmin, nrmin;

bool Check(int time) {
	long long s = 0;
	for (int i = 0; i < N; ++i)
		s += time / truck[i].t * truck[i].c;
	return s >= M;
}

int main() {
	fin >> N >> M;
	for (int i = 0; i < N; ++i) {
		fin >> truck[i].c >> truck[i].t;
		truck[i].t <<= 1;
	}
	for (int step = 1LL << 29; step; step >>= 1) {
		if (!Check(tmin | step))
			tmin |= step;
	}
	++tmin;
	for (int i = 0; i < N; ++i)
		amount[i] = tmin / truck[i].t * truck[i].c;
	sort(amount, amount + N, greater<int>());
	while (M > 0)
		M -= amount[nrmin++];
	fout << tmin << " " << nrmin << "\n";
	return 0;
}