Pagini recente » Cod sursa (job #192060) | Cod sursa (job #1500635) | Cod sursa (job #2398547) | Cod sursa (job #1883224) | Cod sursa (job #3257225)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("garaj.in");
ofstream fout("garaj.out");
struct Camion {
int capacitate, timp;
};
bool BagaCaMerge(long long Tmax, int M, const vector<Camion> camioane, int cam) {
long long nr = 0;
for (int i = 0; i < cam; ++i) {
long long transporturi = Tmax / (2LL * camioane[i].timp);
nr += transporturi * camioane[i].capacitate;
if (nr >= M) return true;
}
return nr >= M;
}
bool comp(Camion xx,Camion yy){
//return xx.capacitate/xx.timp>yy.capaciate/yyy.timp
// posibil sa merga si varinta de mai sus (dupa eficienta), dar e cam ciudat
return xx.timp<yy.timp;
}
pair<long long, int> Timp(int n, int M, vector<Camion>& camioane) {
sort(camioane.begin(), camioane.end(),comp);
long long st = 1, dr = 2LL * 1000 * M, Tmin = dr;
while (st <= dr) {
long long mij = (st + dr) / 2;
if (BagaCaMerge(mij, M, camioane, n)) {
Tmin = mij;
dr = mij - 1;
}
else {
st = mij + 1;
}
}
int Nrmin = n;
for (int i = 1; i <= n; ++i) {
if (BagaCaMerge(Tmin, M, camioane, i)) {
Nrmin = i;
break;
}
}
return {Tmin, Nrmin};
}
int main() {
int n,m;
fin >> n >> m;
vector<Camion> camioane(n);
for (int i = 0; i < n; ++i)
fin >> camioane[i].capacitate >> camioane[i].timp;
// sort(camioane.begin(),camioane.end(),comp);
pair<long long,int> rezultat = Timp(n,m, camioane);
fout << rezultat.first << " " << rezultat.second << '\n';
return 0;
}