Pagini recente » Cod sursa (job #340057) | Cod sursa (job #2169393) | Cod sursa (job #2487127) | Cod sursa (job #2155458) | Cod sursa (job #3040160)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("lapte.in");
ofstream fout("lapte.out");
const int Nmax = 100;
int n, l;
pair<int, int> v[Nmax + 5], previ[Nmax + 5][Nmax + 5];
vector<pair<int, int>> dp;
bool sePoate(int mid){
dp.clear();
int catiA, catiB;
dp.push_back({0, 0});
for(int i = 1; i <= n; i++){
int t = dp.size();
for(int j = 0; j < t; j++){
catiA = mid / v[i].first;
catiB = (mid - catiA * v[i].first) / v[i].second;
while(catiA > 0){
if(dp[j].first + catiA >=l && dp[j].second + catiB >= l){
return 1;
}
dp.push_back({dp[j].first + catiA, dp[j].second + catiB});
catiA--;
catiB = (mid - catiA * v[i].first) / v[i].second;
}
}
}
return 0;
}
pair<int, int> calculMiscari(int mid){
dp.clear();
int catiA, catiB;
dp.push_back({0, 0});
for(int i = 1; i <= n; i++){
int t = dp.size();
for(int j = 0; j < t; j++){
catiA = mid / v[i].first;
catiB = (mid - catiA * v[i].first) / v[i].second;
while(catiA > 0){
dp.push_back({dp[j].first + catiA, dp[j].second + catiB});
previ[dp[j].first + catiA][dp[j].second + catiB] = {dp[j].first, dp[j].second};
if(dp[j].first + catiA >=l && dp[j].second + catiB >= l){
return {dp[j].first + catiA, dp[j].second + catiB};
}
catiA--;
catiB = (mid - catiA * v[i].first) / v[i].second;
}
}
}
return {-1, -1};
}
void reconst(pair<int, int> val){
if(val.first == 0 && val.second == 0){
return;
}
reconst(previ[val.first][val.second]);
fout << val.first - previ[val.first][val.second].first << " " << val.second - previ[val.first][val.second].second << '\n';
}
int main(){
int lft, rgt, mid, sol;
pair<int, int> last;
fin >> n >> l;
for(int i = 1; i <= n; i++){
fin >> v[i].first >> v[i].second;
}
lft = 1;
rgt = 100;
sol = -1;
while(lft <= rgt){
mid = (lft + rgt) / 2;
if(sePoate(mid)){
sol = mid;
rgt = mid - 1;
}
else{
lft = mid + 1;
}
}
fout << sol << '\n';
last = calculMiscari(sol);
reconst(last);
return 0;
}